Is there a way to do a ' ls -R | grep "aname"* | rm; to remove multiple files in multiple directory
I have installed (compiled) emerald. The command make uninstall
didn't work (there is no makefile as it is just a script). So I decided to remove the file manually. But there were a lot of files.
I've tried some things but it didn't work. So I came here to ask for some advice.
- Is there a command with
ls -R | grep blabla*
that I can add to display file directory (it only displays filename) - Is there a true
ls -R | grep bla* | rm
?
Solution 1:
If 'aname' shall be the starting part of the filename, it would be, from the current directory:
find -name "aname" -delete
Btw.:
grep "bla"* somewhere
is almost always false, since grep already makes partial matches, which means, it finds bla, blafasel and xybla with simply
grep bla somewhere
Deleted older part of answer, because of misunderstanding:
From the current directory, if you look for the word 'aname' in all files, you can just use:
find -exec grep "aname" {} ";" -delete
Solution 2:
What you are looking for is a combination of xargs
, find
, and rm
.
find
will make a list of all the files matching your conditions, and then write them (null terminated) to stdout
, which will be piped to xargs
. xargs
will take the null terminated strings and use them as arguments to rm
.
find -L /path/to/dir -name "*name*" -print0 |xargs -0 -r rm
source: http://linuxcommando.blogspot.com/2007/10/find-xargs-pipe.html