Locate a File and Go to It

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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s