I have a directory with several subdirectories; in each of these, I have some files. I want to perform a grep
only for some subdirectories to find those files that match the query and remove them; something like grep -rl --exclude-dir=dir1 --exclude-dir=dir2 HUMAN . | rm
, but I'd prefer not to parse the stdin
from grep
.
I think I have to combine find
and rm
, but I don't know how.
Moreover, it seems that (at least here in Cygwin), I cannot do --exclude-dir={dir1, dir2}, I have to split them. This is a minor problem, but does someone have any idea why this doesn't work?
--exclude-dir={dir1,dir2}
works fine for me inbash
, just remove the space after the comma.find
you can reference one file using{}
within the-exec
option, eg:find . -type f -name *.jar -exec ls -l {} \;
searches for all jar-Files and executes als -l
for each file. Disclaimer: I tried it with CentOS, not with cygwin