Thursday, 6 October 2011

Top 5 Command Line Tip Posts

Linux CLI cheat sheet from Pixel Beat
I'm a big fan of 'Top X Command Line Tips' type posts and I keep meaning to get around to doing my own I've now done my first couple on Apache Access log tips and Top 10 Shortcuts. In the meantime I thought I'd share 5 of my favourite. Numbered but not really in any order.

Actually my favourite of these is 9 ways to recover your screen. that has come in useful countless times.



  1. 25 Sick Linux Commands
  2. 25 Even More Sick Linux Commands
  3. 9 Ways to recover your screen
  4. Command line chea tsheet
  5. How to colour the Bash promtp
Here's a couple of tips that I now use everyday (can't remember if they're covered in the above posts.):
  1. Change to you previous directory
    cd -
  2. Insert the last argument from the previous command
    [ESC]+.
    That's hold down escape and press .
    This is a great one if you're processing a file in multiple steps. The result file is often the last argument of a command then is will be an argument of the next command.
  3. Here's my prompt:
    PS1="\[\e[30;1m\]\u@\h:\[\e[34;1m\]\w\n\`if [ \$? = 0 ]; then echo \[\e[30m\]! \!\[\e[30m\]\$; else echo \[\e[31m\]! \!\[\e[30\;0m\]\$; fi\` \[\e[0m\\]"
    It looks like this:
    user@host:/current/working/directory
    ! 506$
    If the command you run returns an exit status that's not 0, i.e. it fails, then it looks like this
    user@host:/current/working/directory
    ! 506$
It'll definitely have to write my own top tops post.

More on the linux command line: How backgrounds and prompts can means less mistakes and Enabling alt+f and alt+b in gnome terminal