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/
4
  • 1
    by what criteria is last defined? Files are placed in folder in arbitrary order Commented Oct 5, 2017 at 9:49
  • How to get the last N files in a directory? should get you started... Commented Oct 5, 2017 at 10:48
  • @RomanPerekhrest the last 100 files in every single folder Commented Oct 5, 2017 at 16:43
  • 1
    "Last" implies an ordering. What ordering are you using? Date? Name? Size? Something else? Commented Oct 5, 2017 at 20:50

1 Answer 1

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
1

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.