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

    Joined:
    May 16, 2013
    Posts:
    1,466
    Try this in your bashrc:

    Code:
    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.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.