Exclude files from rm -rf based on date
I am using this command to remove files from a directory based on date
Quote:
Which also gets deleted with this command, I can work around this by backing up to different paths etc but I would nevertheless like to know if it's possible to adjust the above command to still delete all content except the .notdelete directory. Thanks |
The easiest way would be to pipe the results of find through grep, then use it as an argument to rm. You could use name patterns with find, but you might not be able to prevent the deletion of the contents of the directory easily.
Code:
rm -rfv $( /usr/bin/find /var/backup/sitebackup/ -mtime +5 -depth | egrep -v '(^|/)\.notdelete($|/)' ) edit: I should have looked at the manpage: Code:
/usr/bin/find /var/backup/sitebackup/ '!' -wholename '*/.notdelete/*' -a '!' -name .notdelete -mtime +5 -exec rm -rf "{}" ";" |
Quote:
Code:
OPERATORS So using something like Code:
-mtime +5 -and -not -iname \*.notdelete\* |
Isn't this what "-prune" is for ?.
|
All times are GMT -5. The time now is 09:30 PM. |