Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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 have set up an alias in my .bashrc as follows:

alias u='cd ..'

All is well in my world... until I type cd .. and cringe that I did not use my incredible new alias. In fact, with this particular thing, it's very ingrained. Hard to change my behavior - I need serious intervention.

So, I naturally tried to set up another alias to keep me from using cd ..:

alias 'cd ..'='echo "Use your alias!"'

But that apparently doesn't work. My thought is that this also might somehow conflict with the u alias, in some sort of infinite loop of aliasing.

Any ideas?

share|improve this question
OK, to note: I don't care if this uses aliases or not - My real goal is to stop myself from using cd .. somehow. Perhaps I should change the question title? – kenny May 7 '11 at 19:47
I used to use cd.. (no spaces) all the time in DOS. Took me a while to break that habit in Linux back in the day. – LawrenceC May 8 '11 at 3:32
up vote 9 down vote accepted

Anything more complicated that supplying a few extra arguments to a command is too much for an alias and requires a function instead. Use builtin cd to call the original.

cd () {
  if [ "$*" = ".." ]; then
    echo 1>&2 'Use your alias instead!'
    return 2
    builtin cd "$@"

If you're running bash ≥4.0, I question the utility of this particular alias. Put shopt -s autocd in your ~/.bashrc, and just type .. or any other directory name to switch to it.

share|improve this answer
I might have to use this to break my cd habit... although... at work I wouldn't have access to zsh autocd... oh choices... – xenoterracide May 8 '11 at 0:18

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.