Answer the question
In order to leave comments, you need to log in
How to delete files by mask in Centos?
Help me write a script in Cron (as I understand it, I will need to add it later as *.sh)
There is a folder with many files, without subfolders, the name of all is similar "1552370165. Asterisk record files). The script should look for files that contain the passage "-180" for example, and delete all these files that are older than a week at the time the script is run. There are a lot of files in the folder, there is no structuring, at the moment there are about 12 thousand of them. and will grow (now I'm considering the option of how to write conversations in folders, but for now I'll have to work with what I have).
I'm afraid that the find command will hang up the server.
Answer the question
In order to leave comments, you need to log in
you did not answer in which part there is an excerpt, we will think that at the end-type f
- only files -mtime +7
older than 7 days -regex ".+190"
- any characters at the end of the file 190 -exe
- execute on it rm -r "{}"
- delete the file which in {} array output from the find, in short, a file name is substituted that meets all the above conditions.
man find
There is a search by mask, search by creation time and performing operations on the found files.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question