Top Ten One-Liners from CommandLineFu

Mar 18 2010 Published by under English,Mac,OS X

Peteris Krumins has done a great job on “Top Ten One-Liners from CommandLineFu Explained”. Here’s my short summary for quick reference:

#1. Run the last command as root

$ sudo !!

#2. Serve the current directory at http://localhost:8000/

$ python -m SimpleHTTPServer

#3. Save a file you edited in vim without the needed permissions

:w !sudo tee %

#4. Change to the previous working directory

$ cd -

#5. Run the previous shell command but replace string “foo” with “bar”

$ ^foo^bar^

#6. Quickly backup or copy a file

$ cp filename{,.bak}

#7. mtr – traceroute and ping combined

$ mtr google.com

#8. Find the last command that begins with “whatever,” but avoid running it

$ !whatever:p

#9. Copy your public-key to remote-machine for public-key authentication

$ ssh-copy-id remote-machine

#10. Capture video of a linux desktop

$ ffmpeg -f x11grab -s wxga -r 25 -i :0.0 -sameq /tmp/out.mpg

That’s it.

No responses yet

Less is better, than tail

Jul 27 2009 Published by under English,OS X

I’ve been using tail to watch my log files for years:

tail -f log/production.log

It works great all the time, until you want to search for something, then you have to ctrl+c and open the file in less or vi.

Maybe there is a better way? After some googling, I found less is the answer:

less +F log/production.log

less +F works exactly like tail -f, with more:

  • Simply press ctrl+c to switch to editing model, so you can scroll backward and using any more/vi command, such as /pattern to search
  • Press shift+f again to switch back to tail model

Anyway, just run man less to find some more information.

8 responses so far