find command -exec
I'd like to stream multiple commands together with the -exec action of the find command. I came across the sh -c "..." construction. Things went well for normally named files, but the odd cases didn't. Is there any way of getting any filename to work with this construct?
The original context:
How can I find all geotagged photos with Yosemite 10.10.5 FINDER
It would seem that if find returned an escaped version of the file name, all would be better
mac $ find /Users/mac/exifin -exec ls {} \;
! one.nef
!"$&()*,:;<=>?@[\]^`{|} other.txt
!"$.dng photocardwithiPhone copy.dng
!$&"()*,:;<=>?@[\]^`{|}.dng photocardwithiPhone-copy.dng
!$.dng photocardwithiphonesmallsize copy.nef
Screen Shot 2018-02-25 at 1.44.02 PM copy.nef single'quote.dng
none.dng {}
/Users/mac/exifin/!
/Users/mac/exifin/!"$&()*,:;<=>?@[\]^`{|}
/Users/mac/exifin/!"$.dng
/Users/mac/exifin/!$&"()*,:;<=>?@[\]^`{|}.dng
/Users/mac/exifin/!$.dng
/Users/mac/exifin/none.dng
/Users/mac/exifin/one.nef
/Users/mac/exifin/other.txt
/Users/mac/exifin/photocardwithiPhone copy.dng
/Users/mac/exifin/photocardwithiPhone-copy.dng
/Users/mac/exifin/photocardwithiphonesmallsize copy.nef
/Users/mac/exifin/Screen Shot 2018-02-25 at 1.44.02 PM copy.nef
/Users/mac/exifin/single'quote.dng
/Users/mac/exifin/{}
mac $ find /Users/mac/exifin -exec sh -c " ls {}" \;
! one.nef
!"$&()*,:;<=>?@[\]^`{|} other.txt
!"$.dng photocardwithiPhone copy.dng
!$&"()*,:;<=>?@[\]^`{|}.dng photocardwithiPhone-copy.dng
!$.dng photocardwithiphonesmallsize copy.nef
Screen Shot 2018-02-25 at 1.44.02 PM copy.nef single'quote.dng
none.dng {}
/Users/mac/exifin/!
sh: -c: line 0: unexpected EOF while looking for matching ``'
sh: -c: line 1: syntax error: unexpected end of file
sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
sh: -c: line 0: unexpected EOF while looking for matching ``'
sh: -c: line 1: syntax error: unexpected end of file
/Users/mac/exifin/!$.dng
/Users/mac/exifin/none.dng
/Users/mac/exifin/one.nef
/Users/mac/exifin/other.txt
ls: /Users/mac/exifin/photocardwithiPhone: No such file or directory
ls: copy.dng: No such file or directory
/Users/mac/exifin/photocardwithiPhone-copy.dng
ls: /Users/mac/exifin/photocardwithiphonesmallsize: No such file or directory
ls: copy.nef: No such file or directory
ls: /Users/mac/exifin/Screen: No such file or directory
ls: 1.44.02: No such file or directory
ls: 2018-02-25: No such file or directory
ls: PM: No such file or directory
ls: Shot: No such file or directory
ls: at: No such file or directory
ls: copy.nef: No such file or directory
sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 1: syntax error: unexpected end of file
/Users/mac/exifin/{}
mac $ find /Users/mac/exifin -exec sh -c " ls '{}' " \;
! one.nef
!"$&()*,:;<=>?@[\]^`{|} other.txt
!"$.dng photocardwithiPhone copy.dng
!$&"()*,:;<=>?@[\]^`{|}.dng photocardwithiPhone-copy.dng
!$.dng photocardwithiphonesmallsize copy.nef
Screen Shot 2018-02-25 at 1.44.02 PM copy.nef single'quote.dng
none.dng {}
/Users/mac/exifin/!
/Users/mac/exifin/!"$&()*,:;<=>?@[\]^`{|}
/Users/mac/exifin/!"$.dng
/Users/mac/exifin/!$&"()*,:;<=>?@[\]^`{|}.dng
/Users/mac/exifin/!$.dng
/Users/mac/exifin/none.dng
/Users/mac/exifin/one.nef
/Users/mac/exifin/other.txt
/Users/mac/exifin/photocardwithiPhone copy.dng
/Users/mac/exifin/photocardwithiPhone-copy.dng
/Users/mac/exifin/photocardwithiphonesmallsize copy.nef
/Users/mac/exifin/Screen Shot 2018-02-25 at 1.44.02 PM copy.nef
sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 1: syntax error: unexpected end of file
/Users/mac/exifin/{}
mac $Mac mini, OS X Yosemite (10.10.5), Fall 2014; iPhone 4 7.1.2