This question is essentially a continuation of this question. I have a directory with a large number of subdirectories. How can I delete part of the files in these directories that are stored there for more than a certain time and with a specific pattern in the name. For example, deleting all files older than 3 months, whose name begins with 'start' ends like this: end.zip .
1 answer
deleting all files older than 3 months, the name of which starts with
startends like this:end.zip
This can be done with the find program:
deletion
for this is the option
-delete. first it makes sense to run without it, to analyze the list of found files.all files
for this is the option
-type f.older than 3 months
depending on what “older” means. if the modification time of the file status is meant, then the option
-ctime +количество_сутокdays will do; if the time of modification of the file's contents, then the option-mtime +количество_сутокdays will do ( and the creation time itself is not saved in any file systems, since it is not required by the standard posix ).whose name begins with
startends like this:end.zipfor this is the option
-name маска. something like-name start\*end.zipor-name 'start*end.zip'.
total see the list:
$ find /путь -type f -ctime +90 -name start\*end.zip remove:
$ find /путь -type f -ctime +90 -name start\*end.zip -delete - And if the task is a little more difficult. The string that consists of
startandend.zipis not in the file name, but in its content? - faoxis - oneit will not “complicate”, but “ask a completely different question.” - aleksandr barakin
find <нужные параметры> | xargs rmfind <нужные параметры> | xargs rm. And the parameters can be found inman find. - Nick Volynkin ♦| xargs rm| xargs rm- absolutely superfluous essence. in the presence of a "live" option-delete. - aleksandr barakin