Hide

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.

Hide

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

change to the previous working directory

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

Alternatives

There are 7 alternatives - vote for the best!

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

as alternative to cd $OLDPWD

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

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
-6

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 270 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 269 weeks ago

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

Comment by CodSpirit 267 weeks and 1 day ago

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

Comment by unixmonkey2498 265 weeks and 4 days ago

comes in handy :)

Comment by chanux 265 weeks and 3 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 258 weeks and 2 days ago

why not just "cd .." ???

Comment by wrongloop 258 weeks 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 257 weeks and 5 days ago

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

Comment by sedcommand 249 weeks and 4 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 243 weeks and 2 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_ 230 weeks and 4 days ago

Seems ?

cd --

? jumps to the ~/ directory?

Comment by hced 139 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 105 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 67 weeks and 2 days ago

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

https://github.com/olafurw/olafurw-home/blob/master/tools/qwe.sh

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 44 weeks and 1 day ago

Your point of view

You must be signed in to comment.

Related sites and podcasts