Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I do this too often:

$ pwd
$ cd # oops - meant to tab-complete something

Can cd defaulting to $HOME be disabled?

share|improve this question
You can always switch back to the previous directory using the cd - command. – jscott May 4 '13 at 11:13

Two options I can think of:

  • you can write an alias to default cd without arguments to whatever you want. This is in the line of using utilities like cdargs or apparix. Personally, I have been using this cd replacement for quite a long time.

  • patch bash to behave differently (bash-4.2/builtins/cd.def). Not sure if changing this default breaks other things, though.

228   if (list == 0)
229     {
230       /* `cd' without arguments is equivalent to `cd $HOME' */
231       dirname = get_string_value ("HOME");
233       if (dirname == 0)
234   {
235     builtin_error (_("HOME not set"));
236     return (EXECUTION_FAILURE);
237   }
238       lflag = 0;
239     }
share|improve this answer
Plenty of options - thanks! I've taken the suggestion to use alias and added a specific example as another answer. – wodow May 4 '13 at 23:54

In bash, if you accidentally change to the wrong directory, you can go back to the previous directory with:

share|improve this answer

This alias seems to do it:

alias cd='HOME= cd'

I don't think it has any dangerous side effects...

share|improve this answer

Your Answer


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.