LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 05-03-2008, 11:45 AM   #1
zeromaster
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
rayfordj
Member
 
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:
Code:
 find /data/files/ -type f -name myfile.txt -exec rm {} \;
If it contains, at least 'myfile' and you are not concerned with case:
Code:
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...
Code:
 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
KenJackson
Member
 
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora, PCLinuxOS
Posts: 590

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


Reply


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


All times are GMT -5. The time now is 01:20 AM.

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