Finding non-jpg files

Dariusz J. Garbowski thuforuk at yahoo.co.uk
Tue Aug 22 23:01:18 UTC 2006


On 08/22/2006 10:00 PM, Dotan Cohen wrote:
> I have a large recursive directory of pictures that was once in a
> windows machine. Now that I have copied it to my linux box, I need to
> remove all the files that are NOT jpgs. How can I list all the files
> in a recursive directory that don't end in ".jpg" or ".jpeg"? A shell
> script would be nice, but even a gui program would help. Thanks.

find DIRECTORY -not -name "*.[jJ][pP][gG]" -and -not -name 
"*.[jJ][pP][eE][gG]" -type f -exec rm -v {} \;

will find all files without .jpg/.jpeg extensions (regardless of 
capitalisation) and will delete them printing filenames of deleted 
files. This command will also correctly handle filenames with space, 
special characters, etc.

*WARNING*: make sure that you pass correct DIRECTORY as this *WILL* 
delete any non jpg file under that directory, *recursively*!

I suggest you run this command first to see what will be deleted:

find DIRECTORY -not -name "*.[jJ][pP][gG]" -and -not -name 
"*.[jJ][pP][eE][gG]" -type f

I warned you!

Regards,
Dariusz







		
___________________________________________________________ 
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com





More information about the kubuntu-users mailing list