Thursday, May 2, 2024
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 17123  / 2 Years ago, thu, october 6, 2022, 1:08:50

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.


More From » command-line

 Answers
3

The simple way:



cd /path/to/directory
rm *_foo_*


or



rm /path/to/directory/*_foo_*


The asterisk (*) matches all characters.



To get explanations about what is being done, use rm with -v option. To be prompted before every removal, use rm with -i option:



rm -vi *_foo_*


See man rm for more info.


[#29452] Friday, October 7, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rinstracte

Total Points: 221
Total Questions: 114
Total Answers: 120

Location: France
Member since Fri, Jan 28, 2022
2 Years ago
;