Change Directories And View Files In One Custom Command

We occasionally enjoy geeking 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 $US1; ls;} Just paste in .bashrc 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.


Comments

    If you don't want/need to change into the dir:

    $ dir
    testdir testing test.log
    $ ls testdir/
    adkfjkdf

Join the discussion!

Trending Stories Right Now