Results 1 to 6 of 6
I have a duplicate bunch of of photos in various subdirectories where the duplicates have had an '_2' added to the file name ... thus all duplicates end in *_2.jpg.
...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 04-10-2009 #1Just Joined!
- Join Date
- Apr 2009
- Posts
- 2
Find cmd can't find "*_2.jpg" files
I have a duplicate bunch of of photos in various subdirectories where the duplicates have had an '_2' added to the file name ... thus all duplicates end in *_2.jpg.
But I cant get the find command to filter these (The aim of game being to -exec rm those buggers.) (I'm using Ubuntu intrepid with bash shell.)
cmd> find . -name "*_2.jpg" # doesn't return anything - zilch
cmd> find . -name "*2.jpg" # returns all those files ending *2.jpg such as '140_4082.jpg' apart from those where the 2 is prefixed with an underscore such as '140_4082_2.jpg'
cmd> find . -name "*_2*" # returns all files such as 'img_2210.jpg' which I don't want to rm but does include those prefixed _2.jpg such as '140_4085_2.jpg' which I do want.
So I can have '.jpg' Or I can have '_' in the expression but it seems I just can't have both at the same time?
Hmmmm - any guru's of find out there - John
- 04-10-2009 #2
Can't think of why this problem would be occurring, as described. It works on my machine...
I don't know how familiar you are with Unix, and I don't want to be insulting - but could this be a case-sensitivity issue? "*_2.jpg" won't match file_2.JPG (nor file_2.jpeg, but that's a different problem...) - you can get around this by using "find -iname" instead of "find -name"...
Among other things, it appears that none of the example patterns you indicated actually included a *_2.jpg file in the results? That might lend extra credence to my theory that this is a capitalization issue...
Alternately, maybe try 'find . -name "*_2.*' - note the dot after the 2... Or 'find . -name "*_2.???"' if you want to get only files that end in underscore-two-dot-(three-character extension)...
- 04-10-2009 #3Just Joined!
- Join Date
- Apr 2009
- Posts
- 2
Please - insult away - I deserve it. Yes - JPG not jpg. I thought it should work .. too tired to think straight.
Thanks tetssujin - John
- 04-15-2009 #4Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 10,143
You need to use single quotes around the file name with the wild-card, not double quotes. IE: find . -type f -name '*_2.jpg'
When you use double quotes, the shell tries to expand it, resulting in incorrect, or in your case, no results. The single quotes "guard" the wild card so it is passed as-is to the find command, which uses it internally with its regular-expression evaluator.Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 06-04-2009 #5
- 06-04-2009 #6


Reply With Quote

