Delete a list of files with find and grep
find . -name '*car*' -exec rm -f {} \;
or pass the output of your pipeline to xargs
:
find | grep car | xargs rm -f
Note that these are very blunt tools, and you are likely to remove files that you did not intend to remove. Also, no effort is made here to deal with files that contain characters such as whitespace (including newlines) or leading dashes. Be warned.
To view what you are going to delete first, since rm -fr
is such a dangerous command:
find /path/to/file/ | grep car | xargs ls -lh
Then if the results are what you want, run the real command by removing the ls -lh
, replacing it with rm -fr
find /path/to/file/ | grep car | xargs rm -fr