|
Home > Archive > Unix Shell > November 2007 > Delete all non *.jpg in a directory and sub directory
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
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.
| |
|
| On Nov 19, 2:18 pm, Eliot <e...@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 {} \;
| |
|
| I should have mentioned I am using busybox so my version of find
doesn't seem to support
find -iname
| |
| Scott McMillan 2007-11-19, 7:26 pm |
| On Mon, 19 Nov 2007 11:18:41 -0800 (PST), Eliot <ebp@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
| |
| Laurianne Gardeux 2007-11-19, 7:26 pm |
| > 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
| |
|
| Thanks again but the ! not operator does not work on the busybox
version of find either ! ;(
Any more . . .
| |
| Ed Morton 2007-11-19, 7:26 pm |
|
On 11/19/2007 2:06 PM, Laurianne Gardeux wrote:
>
>
> rm `ls | grep -v -i jpg`
>
> lg
Hope you don't have a file named "*.*" in your directory ;-).
Ed.
| |
| james19390@yahoo.com 2007-11-19, 7:26 pm |
| On Nov 19, 2:18 pm, Eliot <e...@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@yahoo.com 2007-11-19, 7:26 pm |
| On Nov 19, 2:18 pm, Eliot <e...@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])
| |
| Bill Marcum 2007-11-20, 1:37 am |
| On 2007-11-19, Scott McMillan <smcmillan@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.
| |
|
| Thanks everyone.
The easiest thing turned out to be to download and compile the proper
gnu find!
|
|
|
|
|