Change Directories and View Files in One Custom Command

cdl.pngWe occasionally enjoygeeking out at the command line, so we love timesaving Terminal shortcuts. Reader the-soup suggests a simple tweak that combines two common commands into one: cd and ls, switching to a directory and listing its contents in one line.

Here’s a function to change directory and view files at one time, which I do often.

function cdl { cd $1; ls;}

Just paste in .bashrc (Ed. note: .bash_profile for Snow Leopard) and type cdl directorytoswitchto in Terminal.

Note that this should work with any *nix command line environment, including the Terminal apps in Linux and OS X, or something like Cygwin on Windows systems.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.