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

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

am 19.11.2007 20:18:41 von Eliot

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.

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

am 19.11.2007 20:31:49 von bone

On Nov 19, 2:18 pm, Eliot 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 {} \;

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

am 19.11.2007 20:39:52 von Eliot

I should have mentioned I am using busybox so my version of find
doesn't seem to support
find -iname

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

am 19.11.2007 20:47:59 von Scott McMillan

On Mon, 19 Nov 2007 11:18:41 -0800 (PST), Eliot
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

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

am 19.11.2007 21:06:33 von Laurianne Gardeux

> 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

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

am 19.11.2007 21:30:56 von Eliot

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

Any more . . .

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

am 19.11.2007 23:05:33 von Bill Marcum

On 2007-11-19, Scott McMillan 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.

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

am 19.11.2007 23:05:47 von Ed Morton

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.

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

am 20.11.2007 00:15:22 von james19390

On Nov 19, 2:18 pm, Eliot 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)

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

am 20.11.2007 00:19:03 von james19390

On Nov 19, 2:18 pm, Eliot 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])

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

am 20.11.2007 18:39:35 von Eliot

Thanks everyone.
The easiest thing turned out to be to download and compile the proper
gnu find!