Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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'm adding a couple of aliases to my .bashrc file for some shortcuts I use often, among which are:

alias .="cd /;ls"
alias ..="cd ../;ls"
alias cd="cd $1;ls"
alias ls="clear;pwd;ls"

The effective result being that whenever I navigate to a new directory, the window is cleared and displays the new directory and its contents at the top.

All of these aliases work except for the cd alias. I have tried multiple combinations of trying to cd in to the new directory and run ls there, but it seems like I can only either list the contents of the directory and return to the old directory, or successfully cd in to the directory but with the generated list being from the old directory.

Is there something special that needs to be done when aliasing cd (or any command with arguments) in bash? I feel like this is a relatively simple task but I'm just overlooking something with the syntax.

share|improve this question

migrated from Nov 9 '11 at 13:31

This question came from our site for professional and enthusiast programmers.

Just a note - FYI: . and .. are directory names. . == current directory .. == parent directory. Using them as aliases might cause a script somewhere heartburn. – jim mcnamara Nov 9 '11 at 21:32
Duly noted. I'm just tinkering with bash and C++ on a spare install right now, trying to get my bearings. So I could run sudo rm -rf / and be fine :) but I'll keep that in mind for later scripts. – Zee Nov 11 '11 at 22:12
up vote 9 down vote accepted

Aliases have no parameters, try function instead

cd() { builtin cd "$1" ; ls ; }
share|improve this answer
Thanks man, worked like a charm. Never would've guessed that'd do it either. TIL how to create functions in bash, haha – Zee Nov 11 '11 at 22:07

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.