unix — moving/copying files by date

On the computer nerd front. I’ve been struggling with “How to copy, or move, files in a directory modified within the last day”. Voila I found it. Use the find command.

find . -mtime -1 -exec mv ‘{}’ new_dir \;

find . -mtime -1 -exec cp ‘{}’ new_dir \;

Translation find files in current directory that have been modified within the last day, and then move/copy them to new_dir. Note that you’ve got to create new_dir with “mkdir new_dir” before running this command. And no you can’t just pipe this into xargs.

This A Unix/Linux find Command Tutorial on was helpful. It explains why you can’t use xargs and other arcane moves.

Advertisements

Comments are closed.

%d bloggers like this: