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.
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 {} \;
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
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
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
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 . . .
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.
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)
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])
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.
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!
Linux » comp.unix.shell » Delete all non *.jpg in a directory and sub directory