What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Universal configuration monitoring and system of record for IT.

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags





change to the previous working directory

Terminal - change to the previous working directory
cd -
2009-02-04 22:41:21
User: systemj
Functions: cd
change to the previous working directory


There are 4 alternatives - vote for the best!

Terminal - Alternatives
cd -
2012-07-04 22:34:47
User: Blaskovic
Functions: cd
Tags: cd

as alternative to cd $OLDPWD

2012-04-16 21:18:27
User: khopesh
Functions: cd
Tags: cd

This is like `cd -` but doesn't echo the new directory name, which is preferable (to me) for an alias, e.g.

alias cdo="cd $OLDPWD"
cd -
2013-05-07 14:50:18
User: techie
Functions: cd
Tags: cd

if you cd into a directory then cd into another directory somewhere else then you run the cd - command you will go to the previous directory you was in!! To go back to the other directory just run it again. So if you are working in 2 different directories then this is the perfect command for you.

cd -

Know a better way?

If you can do better, submit your command here.

What others think

cd ./-

if you want to change to a dir named '-'

Comment by eneville 353 weeks and 2 days ago

if you like this also look into pushd/popd. it's in the bash man page i think.

Comment by alexfoo 352 weeks ago

pushd/popd are cool but a bit obscure ... "cd -" is straightforward !

Comment by CodSpirit 350 weeks and 2 days ago

always used pushd/popd for this till now.. but this is awesome =)

Comment by unixmonkey2498 348 weeks and 5 days ago

comes in handy :)

Comment by chanux 348 weeks and 4 days ago

Wow! Using Unix/Linux for 18 years, and only TODAY found this bit of info about so very common command - cd ! Amazing!

Comment by vleolml 341 weeks and 3 days ago

why not just "cd .." ???

Comment by wrongloop 341 weeks and 1 day ago

I've got to remember that one. "cd .." doesn't work for that if the last cd command was "cd ~/foo" rather than "cd bar".

Comment by codetinker 340 weeks and 6 days ago

"cd .." goes to the previous directory in the tree, "cd -" goes to the previous _working_ directory.

Comment by sedcommand 332 weeks and 5 days ago

how about "cd $OLDPWD" ? need to just type in "cd $OL" and tab. bash will take care of the rest :)

Comment by ninadsp 326 weeks and 3 days ago

Oh my god, I have been flubbing with pushd/popd (only work if you know ahead of time) for .. decades. I didn't even know this existed. Damn.

Comment by cj_ 313 weeks and 4 days ago

Seems ?

cd --

? jumps to the ~/ directory?

Comment by hced 222 weeks and 6 days ago

I was always wondering if something like a "cd history" like this existed. Thanks.

But it only remembers the *last* working dir. Is there no way to use it as a stack? Like with pushd/popd? But more automatic?

I was already thinking about aliasing "cd" to "pushd . && cd", but that seems a bit wonky...

Comment by exhuma 188 weeks and 4 days ago

The zsh config "setopt AUTO_PUSHD" automatically pushes to dir stack, and I've aliased "p=popd" so at any point I can type "p" to navigate up my working directory history.

Comment by cec 150 weeks and 2 days ago

I use a little script I threw together where you can bookmark the current directory with a short name.


Found it to be quite handy with large structures. It simply creates .qwe.data in your home folder with the tag and the path.

Comment by olafurw 127 weeks and 1 day ago

Why is this marked as malicious?

Comment by benjabean1 9 weeks and 6 days ago

Your point of view

You must be signed in to comment.