HOWTO copy only newer files and preserve structure of directories

Often we need to copy only recently modified files and keep directories in its original states.
To display just modified files we can use command
# find . -type f -mtime 0
where . (dot) means start search from current directory
-type f means find and display only files otherwise directories appear also in the list
-mtime 0 means modify time was within last 24 hours
It looks good so far? Let’s continue.
# find . -type f -mtime 0 | xargs tar -cf /path_to/archive.tar
found filenames will be piped to tar command. Hence archive.tar contains all freshly changed files.
if any filename contains whitespaces it can be correctly handled with small changes
# find . -type f -mtime 0 –print0 | xargs -0 tar -cf /path_to/archive.tar
And what if we need only updated files in the last 10 minutes? It is not a problem at all.
Replace  -mtime 0 with –mmin -10
# find . -type f -mmin -10 –print0 | xargs -0 tar -cf /path_to/archive.tar

Enjoy!



No comments:

HOWTO: Repair Logitech M325 Mouse

FixIt says that you will find single screw under CE label. It isn't always true.