[X-Unix] Finding Parent Directory of Searched-For File
Philip J Robar
philip.robar at gmail.com
Mon May 4 10:07:41 PDT 2009
On May 4, 2009, at 1:02 AM, Rick Gordon wrote:
> How would I do a recursive search that will provide a path to the
> parent folder of a searched-for file?
>
> For instance, this command will find the file in a recursive search,
> but it provides no information on the path to that file:
>
> (starting from a suitable starting place)
> ls -Rl | grep "Bookmarks.plist"
>
> -rw-rw-rw- 1 mobile mobile 100934 May 3 20:37 Bookmarks.plist
> -rw-rw-rw- 1 mobile mobile 143 Apr 30 22:12
> Bookmarks.plist.anchor.plist
> -rw-rw-rw- 1 root mobile 203551 Apr 9 09:00 Bookmarks.plist.bup
>
> ... will find all instances of files with Bookmarks.plist in the
> name, but does not provide any paths to the found files. How can I
> get the path?
Use find(1) with an absolute path name for the search starting point:
find /place/to/start/search -name Bookmarks.plist -exec ls -l {} +
'{}' is replaced with the name of the current file and '+' means
provide as many files as possible as arguments to the utility being
exec'd each time it's called so as to reduce the number of calls. The
latter may not always be appropriate. If you want the exec'd utility
to be called individually for each file found use an escaped
semicolon, '\;', in place of '+'.
Phil
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2688 bytes
Desc: not available
Url : http://listserver.themacintoshguy.com/pipermail/x-unix/attachments/20090504/8582c3dd/smime.bin
More information about the X-Unix
mailing list