Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I do this too often:

$ pwd
/a/long/long/way/from/anywhere
$ cd # oops - meant to tab-complete something
/home/$USER

Can cd defaulting to $HOME be disabled?

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

3 Answers 3

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");
232
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:

cd $OLDPWD
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

 
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.