Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 954
Courier Avatar asked Feb 19 '26 14:02

Courier


1 Answers

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 "$@"
}
like image 128
John Kugelman Avatar answered Feb 22 '26 05:02

John Kugelman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!