I wanted to know what is the best way to remove any files no matter what their extension is based on a partial name.
Example:
13-05-12_foo_something.jpg
13-06-01_something.png
13-05-05_foo_site.html
rm everything in a directory and within the sub folders with _foo_
in the name.
The simple way:
or
The asterisk (
*
) matches all characters.To get explanations about what is being done, use
rm
with-v
option. To be prompted before every removal, userm
with-i
option:See
man rm
for more info.If you want to do it in all subdirectories too, the easiest way is to enable the globstar shell option:
There should be a commented (i.e. starting with a
#
) line in the default~/.bashrc
(line 29 in mine):Just uncomment that line and you'll have access to some improved bash features.