How to copy all the files been modified for the past twenty four
September 8th, 2009
find . -type f -daystart -mtime -10 -exec ls -l {} \; | cpio -pdmv /output/data
find /var/web/public_html -type f -daystart -mtime -10 | cpio -pdmv /output/data
I have given an explanation of each flag used in the above command as well.
- find , linux command
- . & /home/web1/public_html , specifies the directory to search, in this case the website document root
- -type f , will only search for files and not directories
- -daystart , will tell find to start with today date
- -mtime, tells find to include every thing that was modified on and before a twenty fours hour period
- | , will redirect the output to another binary, in this instance cpio
- cpio, Creates and un-creates archived cpio files. And also is capable of copying files to things other than a hard disk.
- -pdmv,
- -p pass trough (copy in and out)
- -d make dirs
- -m preserve modification time
- -v verbose
- /root/test, is the output directory
For moving the files we can use the below command
find . -name '*.bak' -exec mv '{}' backup_dir/ \;
This would move every file found into backup_dir/.
Categories: System Administrator's Guide