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 file contents. For example, deleting all files older than 3 months that contain a string (or a substring) with the beginning of start and the end of end.zip .
|
1 answer
This answer is essentially a continuation of this answer.
only in view of the fact that the find program “does not know how” to view the contents of files, an addition is required, for example, in the form of a grep program:
$ find /путь -type f -ctime +90 | xargs grep -l 'start.*end\.zip' this command will receive a list of files, the time for which the status is modified is more than 90 days, uncompressed, containing the required sequence of characters (in one line).
The -l option of the grep program is used to display only the names of files in which a match is found with the specified regular expression.
if “everything is ok”, then this list can be sent to the rm program through the pipeline:
$ find /путь -type f -ctime +90 | xargs grep -l 'start.*end\.zip' | xargs rm - Yes, but your last answer is essentially a continuation of this answer: ru.stackoverflow.com/questions/594746/… - faoxis
- @faoxis, in principle, any conveyor in which
findandxargs(and this is a very convenient “couple” in many cases) can be considered a “continuation” of the same story. - aleksandr barakin - Is it possible to find a mention of them on
stackoverflowusing this bundles? - faoxis - This is a completely different question, I understand. :) - faoxis
- one@faoxis , .stackoverflow.com/search?q=find+xargs - aleksandr barakin
|