Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

World cup college
Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

2010-03-18 - Top 10 commands explained
There's a great article by Peteris Krumins explaining the current top 10 commands: http://www.catonmat.net/blog/top-ten-one-liners-from-commandlinefu-explained/
2010-03-03 - Commandlinefu @ SXSW 2010
Am going to be at SXSW this year, in case you want to submit any CLI nuggets or suggestions to me in person. Ping me on the @codeinthehole Twitter account.
2009-09-12 - Email updates now available
You can now enable email updates to let you know each time you're command is commented on.
2009-07-11 - API and javascript blog widget now available
A simple API has been released, allowing commands to be retrieved in various formats. This also allows commands to be embedded on blogs/homepages.
Hide

Tags

Hide

Functions

All commands

All commands from sorted by
Terminal - All commands - 59 results
echo "savedefault --default=2 --once" | grub --batch; sudo reboot
mussh -h host1 host2 host3 -c uptime
chmod -R u=rwX,g=rX,o=rX .
ssh user@remote 'cat >> ~/.ssh/authorized_keys2' < ~/.ssh/id_rsa.pub
ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host
pdftk first.pdf second.pdf cat output output.pdf
tr '\000' '\377' < /dev/zero | dd bs=512 count=200000 status=noxfer | pipebench | sudo dd of=/dev/sdx
2010-08-31 15:38:27
User: Gliktch
Functions: dd sudo tr
2

Note: Replace 200000 with drive bytes/512, and /dev/sdx with the destination drive/partition. ;)

Note: You may need to install pipebench, this is easy with "sudo apt-get install pipebench" on Ubuntu.

The reason I hunted around for the pieces to make up this command is that I wanted to specifically flip all of the bits on a new HDD, before running an Extended SMART Self-Test (actually, the second pass, as I've already done one while factory-zeroed) to ensure there are no physical faults waiting to compromise my valuable data. There were several sites that came up in a Google search which had a zero-fill command with progress indicator, and one or two with a fill-with-ones command, but none that I could find with these two things combined (I had to shuffle around the dd command(s) to get this to happen without wasting speed on an md5sum as well).

For reference, these are the other useful-looking commands I found in my search:

Zero-fill drive "/dev/sdx", with progress indicator and md5 verification (run sudo fdisk -l to get total disk bytes, then divide by 512 and enter the resulting value into this command for a full wipe)

dd if=/dev/zero bs=512 count=<size/512> | pipebench | sudo tee /dev/sdx | md5sum

And this command for creating a file filled with ones is my other main source (besides the above command and man pages, that is - I may be a Linux newbie but I do read!):

tr '\000' '\377' < /dev/zero | dd of=allones bs=1024 count=2k

Hope someone finds this useful! :)

Cheers,

- Gliktch

eog `curl -s http://xkcd.com/ | sed -n 's/<h3>Image URL.*: \(.*\)<\/h3>/\1/p'`
/usr/bin/package-cleanup --oldkernels --count=3
2010-09-02 11:18:13
User: SuperFly
1

Install using yum install yum-utils

Options include:

--oldkernels Remove old kernel and kernel-devel packages

--count=KERNELCOUNT Number of kernel packages to keep on the system (default 2)

use package-cleanup --help for a complete list

tail -f `ls -alst /var/log/maillog* | awk '{print $10} NR>0{exit};0'` | grep "criteria"
mencoder input.flv -ovc lavc -oac mp3lame -o output.avi
curl -sI http://blog.binfalse.de
ram() { for i in /tmp /altroot;do mount -t tmpfs tmpfs $i;done&& for i in /var /root /etc $HOME; do find -d $i |cpio -pdmv /tmp&& mount -t tmpfs tmpfs $i&& mv -v /tmp$i/* $i&& rm -vrf /tmp$i ; done ;} usage: (in rc sequence) ram
2010-08-31 08:25:55
User: argv
Functions: cpio find mount mv rm
1

if you use disk-based swap then it can defeat the purpose of this function.

hdiutil create -size <maxBundleSize> -autostretch -spotlight -fs "MS-DOS FAT32" -type SPARSEBUNDLE -encryption AES-256 -volname <bundleName> <fileName>
2010-08-28 22:18:48
User: Marco
1

Creates an image for using as a "shared folder" by multiple users on the same computer. Mac has a shared folder for the usage by all local users on the same computer, but using this folder has some drawbacks (depending on what the users like to do).

* A file can only be deleted by owner (can be solved by setting sticky bit correctly).

* Files can only be changed by owner (could be solved with help of ACLs, but not all programs supports that - like Photoshop)

This behavior is good if you don't trust the other local users. But if you trust them, and e.g. like to share iPhoto- or iTunes-library, it could become troublesome to manage all that file permission stuff correcly.

So using the image created by this command avoids this drawbacks. This command creates an image, which is

* able to backed up by Time Machine, as it transparently consists of many 8 MB files,

* encrypted by 256 bit AES encryption (if not needed, remove "-encrytion AES-256" part from command),

* ignores files security as it is formatted with MS-DOS FAT32 filesystem,

* automatically grows as necessary (so maxBundleSize can be set to e.g. 1t (1 TB)).

Put the created file to /Users/Shared/ and change file permissions to give read/write access to each user separately by Finder. After that drag that file to startup objects of each user. Put password into keychain access.

wget http://forums.dropbox.com && wget $(cat index.html|grep "Latest Forum Build"|cut -d"\"" -f2) && wget $(cat topic.php*|grep "Linux x86:"|cut -d"\"" -f2|sort -r|head -n1) && rm -rf ~/.dropbox* && rm index.html *.php* && tar zxvf dropbox-*.tar.gz -C ~/
mencoder -forceidx -of lavf -oac copy -ovc copy -o output.flv clip1.flv clip2.flv clip3.flv
ls -w 1 > list.m3u
2010-08-27 07:03:17
User: Tungmar
Functions: ls
1

A short variant if you have only one directory whit only audio files in it.

i=1;for f in *;do mv "$f" $((i++));done
svn propedit svn:ignore .
2010-08-26 06:57:17
User: Tungmar
Tags: svn
1

Standard command, but I always have to search for it... ;-)

cp "/var/lib/mpd/music/`mpc --format '%file%' | head -n1`" /some/where/else
ps ax --format=pid,eip,esp,user,command
2010-09-02 12:40:41
User: cicatriz
Functions: ps
0

'ps' let you specify the format that you want to see on the output.

sudo nvram boot-args="-v"
hdiutil mount -owners on -mountrandom /tmp -stdinpass /path/to/my.sparsebundle
python -c $(echo -e 'import py_compile\npy_compile.compile("/path/to/script.py")');
translate() { echo $1: $(wget -q -O - 'http://www.google.de/dictionary?source=translation&q='$1'&langpair=en|de' | grep '^<span class="dct-tt">.*</span>$' | sed 's!<span class="dct-tt">\(.*\)</span>!\1, !'); }
2010-09-02 00:08:06
User: fpunktk
Functions: echo grep sed wget
0

the google-api gives you only one translation which is sometimes insufficent. this function gives you all translations, so you can choose which one fits best.