lmkavista.blogg.se

Find files by date linux compress old
Find files by date linux compress old












find files by date linux compress old

This (i.e., /usr/bin/[), and not the shell's [ builtin, is what find runs when you use -exec [.

find files by date linux compress old

Ive also seen people relpace the -exec with print0 and pipe the output to xargs, handles unusual filenames better than echo would. man \[ and 16.3 test: Check file types and compare values in the Coreutils docs Is a useful snippet to list files over 2 days old, though it only counts full days, and theres an element of rounding that happens there, so using minutes with the -mmin option may work better.man mv and the GNU Coreutils reference manual (especially 11.4 mv: Move (rename) files) Find And Delete Files Older Than X days In Linux First, let us find out the files older than X days, for example 30 days.man find and the GNU Findutils reference manual.Then find evaluates the next -exec expression, which prints the warning message. But if [ returned false, the file is still there.

find files by date linux compress old

If [ returned false, then the file is gone, so it was moved, so there's no need to do anything. (Many commands' exit statuses are best interpreted as signifying success or failure, but ['s exist status is usually best interpreted as true or false.) you can run: find srcdir -type f -newermt ! -newermt -exec mv -i ) exists (and is a regular file), and returns either true/success or false/failure. last modified in (for example) September 2014.anywhere in srcdir (i.e., including its subdirectories, their subdirectories, etc.).So you want at least find /home/randomcat -mtime +11 -type f -exec gzip \ | bash -xīut in practice you won't speed up a lot your processing.Moving the files, and prompting the user when there are duplicate names:Īs Subv3rsion's and Eric Leschinski's answers show, the -newermt predicate selects files modified more recently than the date (and optional time) specified as its operand. And you don't want it to run on anything else than a plain file (not on directories or devices, not on symbolic links). Do you want the latest files or the files that are older than 2 days Either way you can use the same basic command: zip -r /destinationpath/mediabackup. By default, gzip will remove the uncompressed file (since it replaces it with the compressed variant).














Find files by date linux compress old