perl - Finding directories named "archive" and deleting files -


i have requirement delete files in directories named "archive" older x days. there multiple directories named "archive" located in various depths of directory tree.

my question tool use find directories? first impulse use perl file:find module, have been embarrassed in past finding out shell script one-liner same thing have written multi-line perl script for.

maybe work you:

# delete 1 @ time. find /path/to/your/files* -type f -mtime +10 -exec rm {} \;  # use 1 rm multiple dirs. (gnu find) find /path/to/your/files* -type f -mtime +10 -exec rm {} +  # use 1 rm multiple dirs. (any find) find /path/to/your/files* -type f -mtime +10 -print0 | xargs -0 rm 

in case delete files path, older 10 days. use care. :-)

if want delete files in folder archive should add

-ipath '*/archive/*' 

to

find /path/to/your/files* -ipath '*/archive/*' -type f -mtime +10 -exec rm {} \; 

maybe should test whole scenario writing found files textfile sure correct.

find /path/to/your/files* -ipath '*/archive/*' -type f -mtime +10 > filelist.txt 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -