I wanted to delete the incessant "Thumbs.db" that Windows leaves everywhere, and found three possible solutions:
rm `find /path -name '*.tmp'`
find /path -name \*.tmp | xargs rm
find /path -name "*.tmp" -exec rm {} \;
The first two probably work when there are no spaces in the folder names. The last one works even when there are spaces. I will explain all three.
First:
rm `find /path -name '*.tmp'`
rm
This is the "remove" command. You would say rm file
to remove "file"`find ....`
Quotation marks are used to wrap things that may be interpreted as two commands. E.g., if you say rm find blah
the computer will look for two files, "find" and "blah". The quotation mark found usually to the left of the 1 key is done to let the computer know you want to pass a command. Try running the find /home/user/path -name '*.tmp'
by itself. Let's pull it apart:find
This is the command which is self descriptive/path
This is the path where it should start. It will look recursively through all farther out folders.-name '*.tmp'
The -name
is a flag, letting the computer know that the next thing is the file it should look for.'*.tmp'
Why does this have quote marks? It doesn't really need it in this example, but if you were looking for a file with spaces in it you would need it.Second:
find /path -name \*.tmp | xargs rm
find /path -name \*.tmp
This command is discussed above, the difference to note is the \*.tmp
which I don't know why it is there. Sorry. Anybody? |
This is the "pipe" symbol. It takes whatever the left side makes, and passes it to the right side. In this case, the left side finds the file *.tmp
and the pipe passes the location of that file to the right side.xargs rm
The xargs command is basically a way to pass commands, the important thing is that it is passing a command to do rm
which will remove the file found on the left side of the pipe.Third:
find /path -name "*.tmp" -exec rm {} \;
find /path
Find in the directory "/path"-name "*.tmp"
Look for the file with an extension of "tmp". If you want it to look for "TMP" as well, use -iname
which is case insensetive-exec rm {} \;
The "-exec" is a flag which tells the computer to execute something, in this case the remove command, after it finds a file. Whatever command you pass has to be followed by a semicolon ; So it would be -exec blahblah ;
complete with the space before the semicolon. The backslash character makes sure that the computer knows it is done doing whatever command it was supposed to do, in this case remove the file.rm {}
The rm command removes (deletes) a file. The brackets are a recursive thing, to the computer they mean "Whatever you just found".