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 05-03-2008, 11:45 AM   #1
LQ Newbie
Registered: Nov 2007
Posts: 6

Rep: Reputation: 0
Multiple file deletion

Is there a command to be able to delete a specific filename in a directory and all of its subdirectories with files of the same name?
Old 05-03-2008, 11:53 AM   #2
Registered: Feb 2008
Location: Texas
Distribution: Fedora, RHEL, CentOS
Posts: 488

Rep: Reputation: 78
I'm sure there are any number of ways to accomplish this depending on what exactly you are after.

If you are after, say, to remove all files that are named: myfile.txt that live under: /data/files/ you could use something like:
 find /data/files/ -type f -name myfile.txt -exec rm {} \;
If it contains, at least 'myfile' and you are not concerned with case:
find /data/files/ -type f -iname \*myfile\* -exec rm {} \;
if you are going to go this route, i'd first try the exec with something a little less 'permanent' to make sure that what is to be removed is actually what you want and not anything else...
 find /data/files/ -type f -iname \*myfile\* -exec ls -l {} \;

I'm sure others may even have scripts (in various languages) that are a bit more robust and perform some decent regex evaluations to better narrow your scope of files to act upon.

Hope this helps.
Old 05-03-2008, 01:08 PM   #3
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora, PCLinuxOS
Posts: 666

Rep: Reputation: 91
You could also do a for loop. You can type the loop right on the command line.
cd /the/directory
for x in $(find . -type f -name filename); do rm $x; done


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
File deletion security eldarvanyar Linux - Software 1 06-15-2007 03:57 AM
File and folder deletion Rick069 Linux - Software 5 02-13-2006 10:08 PM
File Deletion mhkhalqani Linux - General 1 10-12-2005 04:08 AM
secure file deletion shawn59 Linux - Security 2 06-12-2005 10:00 PM
Perl and file deletion berry Programming 4 05-29-2002 07:42 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:53 PM.

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