Search code examples
unixfinddirectorycpfilemtime

find and mtime operation excluding folder mtime


Hi there I have a backup shell script executed through crontab but I have a rather large problem. This is the particular line that scans my drive:

find $E -mtime -1 -exec cp -r --parents {} $B/$T \;

where E and B are variables holding directory paths and T holds the current date. It checks for all files that have been edited within the past day and copies them to the new directory. The folder structure is kept intact due to the --parents argument. The problem I have is that this seems to also check the mtime of all folders, meaning that if I were to change a single file in a very large folder, the entire folder would be copied across during backup, taking up an unnecessary amount of disk space. Is there any way I could remove folder mtime from the equation? I guess it might be possible to exclude folders themselves (not their contents) from the search as long as the --parents argument still takes effect.


Solution

  • I'm guessing you want to apply this only to regular files -

    find $E -type f -mtime -1 -exec cp -r --parents {} $B/$T \;
    

    otherwise

    find $E ! -type d -mtime -1 -exec cp -r --parents {} $B/$T \;
    

    to get other types of files as well, skipping the evaluation of age on directories.