Search code examples
bashshellunixcommand-linecd

How to disable cd command-line?


Typing 'cd' alone in unix terminal leads to Home directory. I wish to disable this functionality. Usually I make the error of typing enter just after cd, and then each time I need to comback to the previous working directory. I loose a lot of time by doing so.

To go Home directory, one would instead just need to type cd ~.

Any idea please?


Solution

  • You can use cd - to quickly return to the previous directory ($OLDPWD). In general, I recommend getting used to UNIX as it is. But if you really want to, add this function to ~/.bashrc. It will make cd with no arguments a noop.

    cd() {
        (( $# > 0)) && builtin cd "$@"
    }