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 11-30-2004, 05:32 AM   #1
Registered: Apr 2003
Location: Shandong province China
Distribution: fedora core 1.0
Posts: 206

Rep: Reputation: 30
how to search and delete

I know "locate" can be used to search files,
and "rm" can be used to delete files.
My question is how to search a kind of file,
for example, abc.txt in /dev/hda5 and delete all of them?
thank you.
Old 11-30-2004, 05:46 AM   #2
Senior Member
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,991

Rep: Reputation: 76
You can search for files recursively, including just files on the same partition using the find command. This also lets you execute a command for each file, which could be rm. See
man find
for more.

You will need to specify the mount-point of the partition, not the partition's device-special file; if you don't know where it's mounted then you can find it using
grep /dev/hda5 /proc/mounts
Old 11-30-2004, 05:56 AM   #3
Registered: Nov 2004
Location: Warsaw, Poland
Distribution: Ubuntu
Posts: 76

Rep: Reputation: 15
find . -name blabla.txt -exec rm "{}" \;

If you want to use locate, go ahead (just replace find . -name blabla.txt with locate blabla.txt)
But I'd recommend to be very careful with using it, since you can easily accidentaly remove i.e. all the files with *.txt extension using this kind of stuff.

That's why I usually do it with:

locate *something* > file.txt
And them see how file.txt looks like and use some regexps to modify the file to make it a script.
Then chmod u+x file.txt and ./file.txt to execute. Then I know what I'm doing and no surprises occur.


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
how to search for and delete empty directories? BrianK Programming 4 06-03-2005 08:24 AM
search default: search post title only slackie1000 LQ Suggestions & Feedback 4 03-10-2005 08:50 AM
Quick VIM question (unhighlighting search terms after search) lrt2003 Linux - Newbie 5 05-08-2004 06:21 PM
How to search and delete files in Unix/Linux puzz_1 Linux - General 5 04-09-2004 11:35 AM
Search and Delete ryanstrayer Linux - General 9 02-10-2002 01:27 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:32 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