Sunday, January 24, 2016

Finding Recent Stuff and Doing Stuff to It

Say you want to move every scientific paper you've downloaded recently into the subdirectory 'obsessing-about-thyroid-diseases'

find . -maxdepth 1 -ctime -0.9 -exec mv {} obsessing-about-thyroid-diseases/ \;

This will usually try to move both the current directory and the subdirectory into the subdirectory. Luckily they both fail for different reasons.


Careful Version


Firstly find them with

find . -maxdepth 1 -ctime -1.2 -printf "%f-%c |" -exec echo {} \; 

This will tell you the names of every file and directory whose status has changed less than 1.2 days ago. Then adjust the time until you get the right files

find . -maxdepth 1 -ctime -0.9 -printf "%f-%c |" -exec echo {} \; 

Then make the directory

mkdir -p obsessing-about-thyroid-diseases 

And preview what you're about to do:

find . -maxdepth 1 -ctime -0.9 -printf "%f-%c |" -exec echo mv {} obsessing-about-thyroid-diseases/ \; 

 And finally actually do it:  

find . -maxdepth 1 -ctime -0.9 -printf "%f-%c |" -exec mv {} obsessing-about-thyroid-diseases/ \;

No comments:

Post a Comment