5

Something similar to this Q&A, I know that cd will change current working directory in terminal to a new directory like this:

cd /path/to/new_directory

But I wonder how can I change current working directory only by typing for example:

/path/to/new_directory

followed by Enter, of course. Nothing more.

2 Answers 2

5

I just find out that by activating autocd shell option, using the following command:

shopt -s autocd

then

a command name that is the name of a directory is executed as if it were the argument to the cd command

(from man bash, somewhere at the line 5131).

So it will actually let me use any directory as a command and will cd to it:

cd

To make the change permanently, add the following line to the end of your ~/.bashrc file:

shopt -s autocd
1

This is the default behavior for zsh with the Grml config. zsh is an advanced shell, it has a lot of improvements over bash, the default shell in Ubuntu.

To install zsh, type:

sudo apt-get install zsh

To grab the Grml configuration, run this from your home directory:

wget -O .zshrc http://git.grml.org/f/grml-etc-core/etc/zsh/zshrc
wget -O .zshrc.local  http://git.grml.org/f/grml-etc-core/etc/skel/.zshrc

Then run zsh to start it. If you like it, you can make it your default shell by running the following command:

chsh -s /usr/bin/zsh
3
  • I tagged my Q with bash, so I'm not really interested in zsh. Anyway, +1 for your nice and clear answer. Jul 8, 2014 at 18:59
  • 1
    You don't really need to grab that Grml configuration. The equivalent of shopt -s autocd from bash in zsh is setopt auto_cd. Jul 8, 2014 at 19:06
  • @RaduRădeanu Thanks for the info. I usually recommend the Grml config because it has all the settings people are usually looking for. If you're into fine-tuning your shell, you'll probably end up trying to mimic the zsh/grml behavior. After using it for 2 minutes, going back to bash is like the step back from bash to sh. (Your experience may differ.)
    – kraxor
    Jul 8, 2014 at 19:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .