Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I know of find but it's only valid for filenames, you won't be able to search the context of a file with it, grep will do, but grep will not go into directories, so I don't have a valid answer, sorry.
Actually I do have an answer, look at CPAN for a perl script (or write your own) which going into every subdirectory in a current directory and searches files for a particular string, you can modify the script so it will delete particular files.
"find" is the magic for this trick. See the man page for some more tricks; but given your example of wanting to remove all files that begin with "netscape" do this command:
find / -name "netscape*" -exec rm {} \;
find is the program name
"/" is the location to start "finding"
-name is the path name or reg exp to "find"
-exec defines a command to run on a match
"rm" is the command
"{}" represents the matched path name
"\;" terminates the exec'ed command
I would suggest that you run the command using the -print option instead of -exec to see what files you actually "find".
Note that this command will also "find" directories, but the "rm" won't work on them so they won't be removed and you will get an error.
-type f says only find files
-exec grep -l "netscape" {} \;
grep the found file for netscape only show name
-exec rm {} \;
remove the files that grep lists
To
Malicious
this command will find every file whose filename you specified after the -name tag
so it will not go into the files to search for a particular string, here I found on CPAN http://www.cpan.org/scripts/index.html
look for keywordsearch-1.00 script
it will do the job of finding the files with a specified keyword, modify it so it will delete them.
Instead of rm -r -f use rm -rf
You don't need to specify them seperately in that way for the remove command. Likewise you can look into the -R command also. To decide, because they are both recursive commands, look at the man page to get an idea of what you want rm to do.
man rm
Also look into shred and see if it looks like something you'd like to try.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.