In this article I will show you how to cd into a directory by only typing the directory name. To do this, you have to activate the autocd.
For bash: shopt -s autocd
$ ls -ld naboo
drwxrwxr-x 2 razvan razvan 4096 2012-06-29 20:05 naboo
naboo: command not found
$ shopt -s autocd
As you may observe, when I type the directory name, the shell makes cd to that directory.
If you type shopt -s autocd in the terminal, the setting will discard at the first reboot. To set in persistently, add shopt -s autocd in your ~/.bashrc file:
$ echo "shopt -s autocd" >> ~/.bashrc
For Zsh: setopt autocd
% ls -ld my
drwxrwxr-x 3 razvan razvan 4096 2012-07-01 03:34 my
zsh: command not found: my
% setopt autocd
The same as in bash, with the autocd activated, the shell does cd to the name of the directory written in the terminal.
To make this setting persistent, add “setopt autocd” in the ~/.zshrc:
$ echo "setopt autocd" >> ~/.zshrc