简体   繁体   中英

Move files from folders into a new one

Hy,

I'm facing a problem with this matter, I want to write a bash command, let me clarify this problem:

I have some dirs with pics within:

|-Dir1
|--pic2.jpg
|--pic3.jpg
|--pic4.jpg
|--pic5.jpg
|--n...

|-Dir2
|--pic2.jpg
|--pic3.jpg
|--pic4.jpg
|--pic5.jpg
|--n...

|-Dir3
|--pic2.jpg
|--pic3.jpg
|--pic4.jpg
|--pic5.jpg
|--n...

All I want to do is move just 3 pics from each folder to a new one. It doesn't matter if it's random pictures or whatever.

Any ideas?

Thanks for your help.

start with this... which will move 3 files into another directory

move3.sh

#!/bin/bash
if [ $# -lt 2 ] ; then
  echo "Usage: $0 <SOURCE_DIR> <DEST_DIR>"
  exit 1
fi
if [ ! -d "$1" ] ; then
  echo "$1 is not a directory, please supply a source directory"
  exit 1
fi
if [ ! -d "$2" ] ; then
  echo "$2 is not a directory, please supply a destination directory"
  exit 1
fi
FILES=$(ls "$1" | tail -3)
for FILE in $FILES ; do
  mv "$1"/$FILE "$2"
done

You can then build upon that to send any combination of source/destination directories to be moved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM