Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You can also use `cd -` to return to the previous directory.


git "borrowed" this idea too. You can use `git checkout -` to checkout the last thing you checked out; very handy when merging.


Python sort of did too, you can use _ to access the last-returned variable in the interpreter.

    [testfunc(x) for x in testlist]

    <successful result>

    success = _

    print _

    <successful result>
It's useful when using the interpreter as a calculator, or when you're bashing out some calculation you can never remember how to do properly.


The same thing also works in irb.

    >> "foo"
    => "foo"
    >> bar = _
    => "foo"
    >> bar
    => "foo"


in bash you can use $_ to access the last argument of the previous command. It lets you do things like this:

    $ pwd
    /home/foo
    $ mkdir -p bar/baz/qux && cd $_
    $ pwd
    /home/foo/bar/baz/qux


Yeah but only one directory in the history. With pushd/popd you can navigate as much as you want, an then popd to that directory you intended to bookmark.


yeah, I switched to cd - for a while but got bitten by this too many times.

$ pwd

/some/long/compli/cated/v1.0.7/path/to/_stuff

$ cd /simple/

$ do -stuff

$ cd ./foo

$ do -stuff

$ rem now let's get back to that complicated directory again

$ cd -

oh, wait, I cd'ed twice, shit


If you find yourself in this spot again, Ctrl-r `cd /som` helps.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: