Home > System Administrator's Guide > How to copy all the files been modified for the past twenty four

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,
    1. -p pass trough (copy in and out)
    2. -d make dirs
    3. -m preserve modification time
    4. -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/.

Comments are closed.