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. |
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
Code:
man find 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 Code:
grep /dev/hda5 /proc/mounts |
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. |
All times are GMT -5. The time now is 12:58 PM. |