How do you move files modified after a specific date (say 7 days for example) to another directory? I clumsily tried sending the output of
ls -t | head -n XX
But learnt recently that it isn't a good idea to parse ls.
You are correct that it is best to avoid parsing ls. The solution below uses find. It will, by contrast, work with even the most difficult file names.
To move all files in the current directory modified less than 7 days ago to /destination/path, use:
find . -mindepth 1 -maxdepth 1 -mtime -7 -exec mv -t /destination/path {} +
find . -mindepth 1 -maxdepth 1
This finds files belonging in the current directory (but not the current directory itself).
-mtime -7
This tells find to select only files less than seven days old.
-exec mv -t /destination/path {} +
This tells find to execute a mv command to move those files to /destination/path.
This is efficient because find will replace {} + with many file names so that fewer mv processes need be created.
Not all versions of mv support the -t option. GNU mv (Linux) does.