Skip to main content
edited tags
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 264

I'm attempting to find and copy files that have been modified within the last day. While doing that I'm trying maintain folder structures under dir1dir1. There are many sub directoriessubdirectories under dir1dir1 and data files within those. 

Below is what I cobbled together so far but apparently mtimemtime is not updated on directories if the contents of a file is updated. Also I believe this cp command will copy all of the files in a directory rather than just those that have changed.

find /NAS/data/dir1 -type d -mtime -1 -exec cp -at /mnt/databackup/dir1 {} +

find /NAS/data/dir1 -type d -mtime -1 -exec cp -at /mnt/databackup/dir1 {} +

If I didused -type f-type f it would not retain the folder structure.

I'm attempting to find and copy files that have been modified within the last day. While doing that I'm trying maintain folder structures under dir1. There are many sub directories under dir1 and data files within those. Below is what I cobbled together so far but apparently mtime is not updated on directories if the contents of a file is updated. Also I believe this cp command will copy all of the files in a directory rather than just those that have changed.

find /NAS/data/dir1 -type d -mtime -1 -exec cp -at /mnt/databackup/dir1 {} +

If I did -type f it would not retain the folder structure.

I'm attempting to find and copy files that have been modified within the last day. While doing that I'm trying maintain folder structures under dir1. There are many subdirectories under dir1 and data files within those. 

Below is what I cobbled together so far but apparently mtime is not updated on directories if the contents of a file is updated. Also I believe this cp command will copy all of the files in a directory rather than just those that have changed.

find /NAS/data/dir1 -type d -mtime -1 -exec cp -at /mnt/databackup/dir1 {} +

If I used -type f it would not retain the folder structure.

Source Link

Attempting to only copy files that have changed within the last day while maintaining folder structure

I'm attempting to find and copy files that have been modified within the last day. While doing that I'm trying maintain folder structures under dir1. There are many sub directories under dir1 and data files within those. Below is what I cobbled together so far but apparently mtime is not updated on directories if the contents of a file is updated. Also I believe this cp command will copy all of the files in a directory rather than just those that have changed.

find /NAS/data/dir1 -type d -mtime -1 -exec cp -at /mnt/databackup/dir1 {} +

If I did -type f it would not retain the folder structure.