CDPATH: never type '~' in a shell prompt again

Discussion in 'all things UNIX' started by Gullible Jones, Mar 31, 2015.

  1. Gullible Jones

    Gullible Jones Registered Member

    May 16, 2013
    Try this in your bashrc:

    export CDPATH=".:$HOME:/run/media/$USER:/etc"
    This makes cd look for a directory name first in . (the current dir), then in the list of directories that follows. So you can type e.g. 'cd Documents' from anywhere in your filesystem, and get to $HOME/Documents. This will only be superseded if there is also a 'Documents' dir in your current working dir. Or you can 'cd Backups' to get to that mounted backup drive, 'cd X11' to get to /etc/X11, etc.

    It even works with bash completion. Type 'cd Doc[tab]' and it will complete to 'Documents' or whatever.

    Caveat: you want '.' before anything else in the list, otherwise you may have to specify './' before certain directories in your current working dir.