Live data from Hacker News

Awesome but commonly unknown Linux Commands

anchor.com.au

11–20 of 88 posts

Re: Awesome but commonly unknown Linux Commands

#11
post #4

One I use all the time is this: $ pwd /Users/me/Sites/foo $ pushd . $ cd / $ pwd / $ popd $ pwd /Users/me/Sites/foo Or in English: If you're in a directory that you need to leave but you know you'll go back there in a minute, use "pushd ." to save that directory. Then go off and do whatever you need to, and when you need to return to the saved directory, use "popd" to take you straight back there.

  $ pushd .
  $ cd /
Why not just

  $ pushd /
?

Also, it's not linux-specific, but bash-specific.

Re: Awesome but commonly unknown Linux Commands

#14
post #11
post #4

One I use all the time is this: $ pwd /Users/me/Sites/foo $ pushd . $ cd / $ pwd / $ popd $ pwd /Users/me/Sites/foo Or in English: If you're in a directory that you need to leave but you know you'll go back there in a minute, use "pushd ." to save that directory. Then go off and do whatever you need to, and when you need to return to the saved directory, use "popd" to take you straight back there.

$ pushd . $ cd / Why not just $ pushd / ? Also, it's not linux-specific, but bash-specific.

It's not Linux or Bash specific, pushd and popd work on Windows too, and work on network shares, e.g.

  c:\> pushd \\server\share
  z:\>

Re: Awesome but commonly unknown Linux Commands

#15

On Linux I very regularly use 'strace', to see what a program is currently doing (in terms of syscalls), what files were opened/read/written/closed, etc.

strace is the Daddy of debugging especially when you can attach it to an already existing program using it's PID. I have solved so many permissions errors problems with strace where the application itself just failed without logging anything.

and on OS X you have DTrace (from Solaris), which can be called using dtruss, which is a shell script wrapper around DTrace

also, in developer > applications there is an app called 'Instruments' which is an excellent GUI front-end to DTrace

Re: Awesome but commonly unknown Linux Commands

#16
post #11
post #4

One I use all the time is this: $ pwd /Users/me/Sites/foo $ pushd . $ cd / $ pwd / $ popd $ pwd /Users/me/Sites/foo Or in English: If you're in a directory that you need to leave but you know you'll go back there in a minute, use "pushd ." to save that directory. Then go off and do whatever you need to, and when you need to return to the saved directory, use "popd" to take you straight back there.

$ pushd . $ cd / Why not just $ pushd / ? Also, it's not linux-specific, but bash-specific.

     $ pushd /
oh, neat. Thanks.

Re: Awesome but commonly unknown Linux Commands

#19
post #5
post #4

One I use all the time is this: $ pwd /Users/me/Sites/foo $ pushd . $ cd / $ pwd / $ popd $ pwd /Users/me/Sites/foo Or in English: If you're in a directory that you need to leave but you know you'll go back there in a minute, use "pushd ." to save that directory. Then go off and do whatever you need to, and when you need to return to the saved directory, use "popd" to take you straight back there.

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

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.

Re: Awesome but commonly unknown Linux Commands

#20
post #6
post #5

Earlier quoted context omitted.

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]

    

    success = _

    print _

    
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.
Post reply on HN