Very simple CLI question
Very dumb question..
How do I apply a command like ls or rm to all files in all the directories below the current one (to arbitrary depth)? E.g. suppose I want to delete all files that have a filename containing a specific pattern without knowing (or caring) which directory they're in. I know about locate and find; I want to use something like: Code:
rm -ir */*/*.~lock* |
the -R flag is probably what you would want. Try doing a "man rm" for details on your particular distro.
|
Quote:
Quote:
|
You'll need to use the "find" command with -name to identify files by pattern and then the "-exec" to apply certain commands to each found file.
|
Yes, the "-exec" parameter for the find command is great.
So it would be something like the following example, if you wanted to delete all files that had a ".tmp" extension... (be sure you're already in the folder where you want to start looking)... find . -name *.tmp -exec rm -f {} \; I suggest running this, first, just to make sure the output is what you want to delete... find . -name *.tmp So if what it spits out looks like the files you want to nuke, then go back add the "-exec..." stuff as show in the first command above. |
Quote:
I had been using that other great Linux command -- rsync -- to synchronise several disks but it's additive; delete a file somewhere and you get it straight back on the next rsync run. I wanted a simple way to prune junk selectively. Many thanks. EDIT: Cross posts -- thank you as well Transformania ! EDIT again: in fact I used Code:
find . -name *.~lock* -exec rm -i {} \; |
Quote:
Code:
find . -name *.~lock* -exec rm -i '{}' \; |
Excellent! Many thanks.
|
All times are GMT -5. The time now is 03:50 PM. |