Delete all non *.jpg in a directory and sub directory

I would like to be able to delete all files from say
/home/me/pics/
that aren't pictures, I have tried using find *.[\^Jj][\^Pp][\^Ee]
[\^Gg]
but it doesn't work.
I would like to delete all files not matching
*.jpg
*.jpeg
and be case insensitive. So *.JPEG or *.JPg does not get deleted.

Thanks a lot.
Eliot [ Mo, 19 November 2007 20:18 ] [ ID #1873842 ]

Re: Delete all non *.jpg in a directory and sub directory

On Nov 19, 2:18 pm, Eliot <e... [at] hotmail.com> wrote:
> I would like to be able to delete all files from say
> /home/me/pics/
> that aren't pictures, I have tried using find *.[\^Jj][\^Pp][\^Ee]
> [\^Gg]
> but it doesn't work.
> I would like to delete all files not matching
> *.jpg
> *.jpeg
> and be case insensitive. So *.JPEG or *.JPg does not get deleted.
>
> Thanks a lot.

check output of
find . ! -iname "*.jpeg" ! -iname "*.jpg"

add to delete:
-exec rm {} \;
bone [ Mo, 19 November 2007 20:31 ] [ ID #1873845 ]

Re: Delete all non *.jpg in a directory and sub directory

I should have mentioned I am using busybox so my version of find
doesn't seem to support
find -iname
Eliot [ Mo, 19 November 2007 20:39 ] [ ID #1873846 ]

Re: Delete all non *.jpg in a directory and sub directory

On Mon, 19 Nov 2007 11:18:41 -0800 (PST), Eliot <ebp [at] hotmail.com>
wrote:

>I would like to be able to delete all files from say
>/home/me/pics/
>that aren't pictures, I have tried using find *.[\^Jj][\^Pp][\^Ee]
>[\^Gg]
>but it doesn't work.
>I would like to delete all files not matching
>*.jpg
>*.jpeg
>and be case insensitive. So *.JPEG or *.JPg does not get deleted.
>
>Thanks a lot.

Try:

find ./ ! -iname "*.jpeg" -a ! -iname "*.jpg

Or, if your find doesn't have the iname option, this should help (all
one line):

find ./ ! -name "*.[J,j][P,p][G,g]" -a ! -name
"*.[J,j][P,p][E,e][G,g]"



Scott McMillan
Scott McMillan [ Mo, 19 November 2007 20:47 ] [ ID #1873847 ]

Re: Delete all non *.jpg in a directory and sub directory

> I would like to be able to delete all files from say /home/me/pics/
> that aren't pictures, I have tried using find *.[\^Jj][\^Pp][\^Ee]
> [\^Gg]
> but it doesn't work.
> I would like to delete all files not matching *.jpg
> *.jpeg
> and be case insensitive. So *.JPEG or *.JPg does not get deleted.

rm `ls | grep -v -i jpg`

lg
Laurianne Gardeux [ Mo, 19 November 2007 21:06 ] [ ID #1873849 ]

Re: Delete all non *.jpg in a directory and sub directory

Thanks again but the ! not operator does not work on the busybox
version of find either ! ;(

Any more . . .
Eliot [ Mo, 19 November 2007 21:30 ] [ ID #1873851 ]

Re: Delete all non *.jpg in a directory and sub directory

On 11/19/2007 2:06 PM, Laurianne Gardeux wrote:
>>I would like to be able to delete all files from say /home/me/pics/
>>that aren't pictures, I have tried using find *.[\^Jj][\^Pp][\^Ee]
>>[\^Gg]
>>but it doesn't work.
>>I would like to delete all files not matching *.jpg
>>*.jpeg
>>and be case insensitive. So *.JPEG or *.JPg does not get deleted.
>
>
> rm `ls | grep -v -i jpg`
>
> lg

Hope you don't have a file named "*.*" in your directory ;-).

Ed.
Ed Morton [ Mo, 19 November 2007 23:05 ] [ ID #1873854 ]

Re: Delete all non *.jpg in a directory and sub directory

On Nov 19, 2:18 pm, Eliot <e... [at] hotmail.com> wrote:
> I would like to be able to delete all files from say
> /home/me/pics/
> that aren't pictures, I have tried using find *.[\^Jj][\^Pp][\^Ee]
> [\^Gg]
> but it doesn't work.
> I would like to delete all files not matching
> *.jpg
> *.jpeg
> and be case insensitive. So *.JPEG or *.JPg does not get deleted.
>
> Thanks a lot.

rm /home/me/pics/!(*jpg|*jpeg)
james19390 [ Di, 20 November 2007 00:15 ] [ ID #1874642 ]

Re: Delete all non *.jpg in a directory and sub directory

On Nov 19, 2:18 pm, Eliot <e... [at] hotmail.com> wrote:
> I would like to be able to delete all files from say
> /home/me/pics/
> that aren't pictures, I have tried using find *.[\^Jj][\^Pp][\^Ee]
> [\^Gg]
> but it doesn't work.
> I would like to delete all files not matching
> *.jpg
> *.jpeg
> and be case insensitive. So *.JPEG or *.JPg does not get deleted.
>
> Thanks a lot.

Sorry. For case insensitive:
rm /home/me/pics/!(*[Jj][Pp][Gg]|*[Jj][Pp][Ee][Gg])
james19390 [ Di, 20 November 2007 00:19 ] [ ID #1874643 ]

Re: Delete all non *.jpg in a directory and sub directory

On 2007-11-19, Scott McMillan <smcmillan [at] twmi.rr.com> wrote:
> find ./ ! -iname "*.jpeg" -a ! -iname "*.jpg
>
> Or, if your find doesn't have the iname option, this should help (all
> one line):
>
> find ./ ! -name "*.[J,j][P,p][G,g]" -a ! -name
> "*.[J,j][P,p][E,e][G,g]"
>
You don't need the commas.
Bill Marcum [ Mo, 19 November 2007 23:05 ] [ ID #1874649 ]

Re: Delete all non *.jpg in a directory and sub directory

Thanks everyone.
The easiest thing turned out to be to download and compile the proper
gnu find!
Eliot [ Di, 20 November 2007 18:39 ] [ ID #1874659 ]
Linux » comp.unix.shell » Delete all non *.jpg in a directory and sub directory

Vorheriges Thema: Postscript Level 3 text to PS conversion tool
Nächstes Thema: pdftk in script does not work: does in shell window.