I want to remove all the .jpg files from my Music folder in order to save room. My Music folder contains subfolders, and I would like to know if there is a command to remove all the .jpg files from all these folders regardless of their level. Thanks for your help!
A quick and clean solution for the command line would be
.
tells to start searching in the current folder.-type f
tells find only to look for files.-iname
makes the search case insensitive.-delete
tells find to delete/remove all files found.CAUTION! I recommend running the command without
-delete
first to get a list of the files that will be removed when-delete
is included in the command. This way a small typo won't delete anything you didn't intend to.For more information on how to use
find
and what it can do seeman find
Note that
find
will not produce any output when-delete
is used.Regarding the comment on multiple extensions
find . -type f \( -name \*jpg -o -name \*png \) -delete
( .. )
Group expression. Needs to be escaped from the shell, hence\( .. \)
in the example-o
logical orSo the above example will match any file which has either
jpg
orpng
at the end of it's name. More extensions can be added in the same way. Just make sure to remember-o
between every-name
statement, if-o
is not specifiedfind
will default to-a
(and) which won't work since a file can't end in bothjpg
andpng
at the same time.This should do it
which will remove all .JPG files within the Music folder.
The easiest way (if you are using Ubuntu Desktop):
Go to your Music folder in Nautilus, press Ctrl+F and search for
.jpg
.& then delete it
You can also change the location and you can make your search more specific.
Updated
Be More specific after searching
.jpg
Clicking on green buttonSelect File type Picture
& then removejpg
from search only.
dot & thenreload
as shown in pic belowBash's
shopt -s globstar
can be useful here for recursive globbing: