A few helpful bash command-line one-liners


[HT Peter, commandlinefu]

Query SVN log history and filter by username

svn log | sed -n '/username/,/-----$/ p'

Run the last command as root

sudo !!

Save a file you edited in vim without the needed permissions

:w !sudo tee %

Why is this command so awesome? Peter described it quite well:

This happens to me way too often. I open a system config file in vim and edit it just to find out that I don’t have permissions to save it. This one-liner saves the day. Instead of writing the while to a temporary file :w /tmp/foobar and then moving the temporary file to the right destination mv /tmp/foobar /etc/service.conf, you now just type the one-liner above in vim and it will save the file.

Change to the previous working directory

cd -

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

^foo^bar^

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

!whatever:p

Copy your public-key to remote-machine for public-key authentication

ssh-copy-id remote-machine

Capture video of a linux desktop

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

No related content found.

Leave a comment