views:

31

answers:

1

I have a laptop installed with Ubuntu 10.04. I migrated some of my files from one computer to this computer. But there are some files like Thumbs.db file whose every occurrence I want to get rid of.

I tried using

locate Thumbs.db | rm

But dis didn't worked out (and clearly it should not). Then I tried using following, but quite expectedly none of them worked out :

locate thumbs.db > rm
locate thumbs.db < rm

As everyone here, might have pointed out that I am having a hard time using pipeline and want to just clear my concept using this as an example. I have read the basics but still not able to intitutively able to apply it.

Please tell me how to work this out. I will try to figure out rest for myself :D .

+1  A: 

You may want try:

find /mnt/something -iname 'thumbs.db' -exec rm -v {} \;

or if you really want use pipe you may want try

find /mnt/something -iname 'thumbs.db' | xargs rm -v

-iname will search for 'Thumbs.db' and 'thumbs.db'. Check man for more info.

change /mnt/something for your path.

Edit:

I think you can also try it:

find /mnt/someting -iname 'thumbs.db' | while read junk; do rm -v "$junk"; done

It should work with dirs what contain space in name etc.

Piotr Karbowski
One problem with the above is that say I have a directory "New Directory" which have Thumbs.db file. When I issue the above command it tries to delete Thumbs.db from "New" and "Directory" directories which doesn't exist on my computer.
abhishekgupta92
Thats where pipe and xargs sucks, if you will use the one with -exec it will work as you want.
Piotr Karbowski
find and xargs don't suck. Just use `find ... -print0 | xargs -0 ...`. This uses null characters to separate the filename, so spaces are no longer special.
Ryan Thompson
@Ryan can you please elaboarate more on its usage or edit the code of Piotr to meet the requirement
abhishekgupta92
`find /mnt/something -iname 'thumbs.db' -print0 | xargs -0 rm -v`
Ryan Thompson