The first time I came up with this script was a long time ago and I did it with Perl. Today I feel like doing such a thing using Ruby.
Basically the script takes a number of directories and an optional pattern (last argument) from the command line. If either a directory or a pattern is not providen, it looks for in the current directory, and use a default pattern.
The script searches for those files matching the pattern and deletes thoses files from the system. Besides, it checks the owner of the files is the same that is running the script.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
The default pattern is set to delete backup files ending with ”~”. Below is the ouput:
1 2 3 4
You might change the pattern from the command line:
1 2 3 4 5
This is how it works, I did not try too many different patterns beyond these.