0

Every folder here got about 1000 items, and I wish to "move" the last 100 items to another directory by creating the same folder name and store it.

Example:

/original/folder1/
/original/folder2/
       ...
/original/folder50/

Ibwish to move the last 100 items from every folder above to destination below which is not created at the very beginning.

/dest/folder1/
/dest/folder2/
      ....
/dest/folder50/
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
JefferyLR
  • 119

1 Answers1

0

This is a horrible solution. But it will work. Pay attention to the paths and what cut field to set based on your directory structure.

for i in `find original/ -type d | grep -v 'original/$'`;
  do foldernames=`echo $i | cut -d "/" -f 3-`; 
  mkdir -p dest/$foldernames ; 
  ls $i | tail -n 100 | xargs -i -t mv $i/{} dest/$foldernames ; 
done