Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-17-2006, 05:39 AM   #1
Registered: Jan 2006
Location: France
Distribution: Debian Wheezy, Webmin + Virtualmin (remote dedi)
Posts: 214

Rep: Reputation: 30
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
Old 08-17-2006, 05:53 AM   #2
spirit receiver
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
The find command should be sufficient, in particular its -delete and -name switches. Have a look at "man find".
Old 08-17-2006, 05:55 AM   #3
Registered: Aug 2003
Location: Montpellier, France, Europe, World, Solar System
Distribution: Debian Sarge, Fedora core 5 (i386 and x86_64)
Posts: 262

Rep: Reputation: 30
'find' is your friend:

Delete all thumbs.db in current dir and subdirs:
find . -name thumbs.db -exec /bin/rm {} \;
Delete all files not being .txt or .TXT files:
find . -type f ! -iname "*.txt" -exec /bin/rm {} \;
For more options:
man find
Old 08-18-2006, 03:40 AM   #4
Registered: Jan 2006
Location: France
Distribution: Debian Wheezy, Webmin + Virtualmin (remote dedi)
Posts: 214

Original Poster
Rep: Reputation: 30
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 !


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
is it possible to identify the kind of file descriptor? Thinking Programming 2 08-11-2005 05:43 AM
What kind of file is this? stefaandk Linux - Newbie 1 06-10-2005 08:58 AM
What kind of file is *.asc? CodeWarrior Linux - General 4 07-10-2004 11:45 PM
How would you cp a file to multi subdirs? m0rl0ck Linux - General 2 03-04-2003 12:41 AM
Diffrent kind of file sharing sscharbo Linux - Networking 4 04-12-2001 06:06 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:48 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration