V
V
Vasya Pupkin2019-07-16 09:51:40
linux
Vasya Pupkin, 2019-07-16 09:51:40

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

3 answer(s)
V
Victor Taran, 2019-07-16
@Desert-Eagle

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.

R
Radjah, 2019-07-16
@Radjah

man find
There is a search by mask, search by creation time and performing operations on the found files.

2
20ivs, 2019-07-16
@20ivs

no matter how much Asterisk deployed, conversation records are always sorted by directories (date, number). for example:
16_07_2019
100
101
etc.
see what you have with the config. it's easier than building scripts yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question