Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 5 down vote accepted

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 your ~/.bashrc file:

shopt -s autocd
share|improve this answer

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
share|improve this answer
    
I tagged my Q with bash, so I'm not really interested in zsh. Anyway, +1 for your nice and clear answer. –  Radu Rădeanu Jul 8 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. –  Radu Rădeanu Jul 8 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 at 19:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.