LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Deleting all of a kind of a file even in subdirs ? (https://www.linuxquestions.org/questions/linux-newbie-8/deleting-all-of-a-kind-of-a-file-even-in-subdirs-474701/)

Sabinou 08-17-2006 05:39 AM

Deleting all of a kind of a file even in subdirs ?
 
Hello folks :)

I'm wondering is there is a way to run a precise action :
deleting all of a certain kind of files starting from a folder and including all the subfolders.

For instance, with many partitions inherited from MS Windows, I have "thumbs.db" present. I'd like to just let the system delete them for me, if you see my Idea.
Or another example, I have another place where I accidentally downloaded not only texts but also lots of annoying little pictures, i'd like to be able to delete anything not .txt in the folder and its subdirs.

In other words, I'd like a way to do something like "rm thumbs.db -case-insensitive -in-every-dir-and-subdir", or "rm anything-not-*.txt -in-every-dir-and-subdir"...

Would you know if that's possible ?

I don't know how to do it, but considering the power of linux scripting, which is still new to me, hope is allowed :)

spirit receiver 08-17-2006 05:53 AM

The find command should be sufficient, in particular its -delete and -name switches. Have a look at "man find".

zeitounator 08-17-2006 05:55 AM

'find' is your friend:

Delete all thumbs.db in current dir and subdirs:
Code:

find . -name thumbs.db -exec /bin/rm {} \;
Delete all files not being .txt or .TXT files:
Code:

find . -type f ! -iname "*.txt" -exec /bin/rm {} \;
For more options:
Code:

man find

Sabinou 08-18-2006 03:40 AM

Another useful command, find, and another useful way of proceeding, adding the -exec... commands, that's a nice day, I learned great stuff today :)

Thanks, Zeitonator and Spirit_Receiver !


All times are GMT -5. The time now is 08:21 PM.