Bash CD – Change Directory by Just Typing the Directory’s Name

bashcd-commandcommand linedirectoryshell

I either had this somewhere 20 years ago or I dreamed about it.

Basically:

If if type blobblob I get
blobblob: command not found

Fair enough.

I would like it so that when my shell gets those errors – command not found – it checks to see if a directory exists with that name ('blobblob') and if it does it cd's to that directory.

I'm sure there are some reasons for not doing this or doing it with caution.
I just think it would be pretty neat though and I would like to give it a try by finding how somewhere (like here!).

I have no idea how to do the kinda shell programming this might imply.

Best Answer

  • Bash: shopt -s autocd
  • Zsh: setopt autocd
  • tcsh: set implicitcd

Also, 'autojump' is a useful tool. Once installed it remembers directories so that you can type j abc and if you've visited abc before, say x/d/f/g/t/abc then it will cd to there!
https://github.com/joelthelion/autojump

Related Question