Hai’s Blog

May 4, 2009

Locate a File and Go to It

Filed under: Unix — Hai @ 3:58 am

I often need to find a file, then cd to its directory. This command will do both, provide that the file’s name is unique enough:

$ cd $(dirname $(find ~ -name emails.txt))

Please note that the above command works for bash shell, but not csh: csh’s equivalent to the $( … ) construct is the ` … ` construct which the bash shell also understands. However, the “ construct does not allow for nesting.

No Comments Yet »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.