Skip to content
Tools for making directory navigation a bit easier in a bash shell
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


bashcd is a collection of tools meant to make navigating the command line a bit easier. The following commands are included:

fcd <dirname>

Recurses subdirectories using the find command in order to find a directory. This is probably the most reliable of the methods I provide to recurse subdirectories, but there is one complication -- if you have a particularly large subtree, it may be slow.

filecd <filename>

Switch to the directory which contains the identified file. For example, if you were in the home directory and if you had a file named /home/mflower/code/opensource/, typing "filecd" would switch to the /home/mflower/code/opensource directory.

dcd <directory alias>

Dcd keeps an internal list of directory aliases. For example, if you wanted to keep a directory alias for the /home/mflower/code/opensource directory, I would type dcd -a opensource from that directory. In the future, typing dcd opensource would switch me to that directory. dcd -l gives you a list of all current aliases. Type dcd -h for further details.

lcd <dirname>

Similar to fcd, except not limited to only subdirectories. Lcd can switch to any directory on your machine which is currently in the locate database. This is great if you have a well updated located database.

mcd <dirname>

Very similar to lcd except that it is specific to mac. It uses the mdfind command line utility which uses the underlying indexing that happens constantly on the mac.

ucd <dirname>

Switch to a parent directory of the current directory. For example, if the current directory is /home/mflower/code/opensource, you could use ucd home to switch to the /home directory.


Copy the file to a local file called .bashcd in your root directory. Add the following line to your .profile, .bashrc, or .bash_profile.

source .bashcd

Once you restart your terminal bashcd will be automatically initialized. If you wish to try it out without installing it permanently, you can type "source " (without the < and > marks).

If you have problems with scripts complaining about dcd after doing this, consider wrapping the source in a check to make sure you are in an interactive shell:

if [[ $- == *i* ]]; then
    source .bashcd


All commands have a help file built into them. Type the command and press enter to see the help. I've also copied these help files into the wiki:


All of the above features have bash completion built in. After you have typed the name of the command, hit the tab key for completion.

If there are multiple completions for the command you have entered, bashcd will show a list of potential directories to go to.
For example:

/Users/mflower/code/code/a $ ucd code
Please choose a directory to change to
  1. /Users/mflower/code 
  2. /Users/mflower/code/code 

Your choice: 1

/Users/mflower/code $
Something went wrong with that request. Please try again.