Stack Exchange Network
Stack Exchange network consists of 181 Q&A communities including
Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack Exchange
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.
Sign up to join this community
Anybody can ask a question
The best answers are voted up and rise to the top
9 years, 1 month ago
I changed my wordpress theme. The older one created so much images on server. My new theme doesnt need them, so I want to remove all. How can I do that?
I want to delete:
Using Digitalocean, Ubuntu 13.10.
Apr 5, 2014 at 22:15
Ibrahim Mumcu Ibrahim Mumcu
663 1 1 gold badge 5 5 silver badges 5 5 bronze badges
find to recursively find and delete files with "text" in their names:
find -type f -name '*text*' -delete
You might also want run
find -type f -name '*text*' (without the
-delete) before that to make sure you won't delete any files you didn't intend to delete.
In fact, you can place wildcards anywhere in the search string, so
-name '12_angry_men_lone_holdout-*.jpg' might be more suitable in your case.
Apr 5, 2014 at 22:49
1,300 11 11 silver badges 19 19 bronze badges
If they are in the same folder use * wildcard to achieve that:
text is string that filename contains.
Apr 5, 2014 at 22:32
Michal Fudala Michal Fudala
816 1 1 gold badge 8 8 silver badges 9 9 bronze badges
find . -type f -name '*[0-9]x[0-9]*' -delete
Run this in the parent directory.
This is going to delete all files that have a digit followed by an 'x' character followed by another digit in their name.
Still be careful, this might delete original files too, if their name contains the above pattern (unlikely). Run it first without '-delete' to see if you have any files that have such a name. If that's the case, you'll just need to find a more restrictive pattern.
Feb 6, 2018 at 16:11
21 2 2 bronze badges
rm -rf 12_angry_men_lone_holdout-*
keep 12_angry_men_lone_holdout.jpg and remove files with dimensions (290x166)
And please remember
rm -rf 12_angry_men_lone_holdout.*
will delete the default file too, that you needed.
23.4k 16 16 gold badges 74 74 silver badges 100 100 bronze badges
Sep 4, 2016 at 4:28
11 2 2 bronze badges
I found out, that if you want to delete a directory which starts with a specific letter, you can use the next command:
Let's say you have created the next folders:
rm -rf B* b*
This will delete all directories starting with those letters (uppercase B and lowercase b).
After executing this command, you will only keep the folder named
Aka. You can check it using
ls to list the remaining folders in the current directory.
116k 54 54 gold badges 313 313 silver badges 488 488 bronze badges
Jun 2, 2020 at 16:24
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our
Accept all cookies
Necessary cookies only
man rmto see the manual page of the rm command.