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 - 5,761 results
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.

lesz() { [ -f "$@".gz ]&& gzip -dc $@ |less || less $@ ;} usage: lesz <txt file or txt.gz file>
tree -fi /directory/path/* | grep "\.js"
2010-09-01 15:19:29
User: ozgurkuru
Functions: grep
0

file listing in /directory/path/* of specific files such as javascript(js) .

chmod -R a=rw,u=+X .
tail -f `ls -alst /var/log/maillog* | awk '{print $10} NR>0{exit};0'` | grep "criteria"
while [[ COUNTER -le 10 && IFS=':' ]]; do for LINE in $(cat /tmp/list); do some_command(s) $LINE; done; COUNTER=$((COUNTER+1)); done
2010-09-01 15:09:59
User: slashdot
Functions: cat
0

At times I find that I need to loop through a file where each value that I need to do something with is not on a separate line, but rather separated with a ":" or a ";". In this instance, I create a loop within which I define 'IFS' to be something other than a whitespace character. In this example, I iterate through a file which only has one line, and several fields separated with ":". The counter helps me define how many times I want to repeat the loop.

pdftk first.pdf second.pdf cat output output.pdf
chmod -R u=rwX,g=rX,o=rX .
http://www.passwordunlocker.com/knowledge/remove-rar-password.html
2010-09-01 03:39:52
User: yitiana
-27

Want to remove RAR password to gain access to the files? Follow the sep-by-step guidance in the article and try to recover RAR password with 3 different attack options: brute-force attack, brute force with mask and dictionary attack.

http://www.passwordunlocker.com/knowledge/create-and-remove-sql-password.html
2010-09-01 01:59:34
User: yitiana
-25

This article introduces a step-by-step guide to create a password for SQL server. It also tells you how to easily remove SQL Server password with SQL password remover if you forget your SQL Server password.

rename 'y/ /_/' *
mencoder input.flv -ovc lavc -oac mp3lame -o output.avi
echo "savedefault --default=2 --once" | grub --batch; sudo reboot
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=output.pdf -dBATCH first.pdf second.pdf
iconv -f utf8 -t utf16 /path/to/file
curl -sI http://blog.binfalse.de
for i in `find .`; do [ -d $i ] && chmod 755 $i || chmod 644 $i; done
2010-08-31 22:27:32
User: binfalse
Functions: chmod
-3

Reconstruct standard permissions for directories and files in current directory

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

ffmpeg -i "inputFile.avi" -f psp -r 29.97 -b 512k -ar 24000 -ab 64k -s 368x208 M4V00002.MP4
eog `curl -s http://xkcd.com/ | sed -n 's/<h3>Image URL.*: \(.*\)<\/h3>/\1/p'`
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.

find -type f -iname '*.html' | while read i ; do sed '/BAD_SCRIPT_LINE/d' -i "$i" ; done
2010-08-31 08:11:07
User: John_W
Functions: find read sed
-2

Better than using grep and xargs, also you only need to provide the script once.

gconftool-2 --set /apps/metacity/global_keybindings/panel_main_menu --type string "Super_L"
grep -ZlRr -e BAD_SCRIPT_LINE * |xargs -0 sed -i 's/BAD_SCRIPT_LINE//g'
2010-08-30 22:12:57
User: homoludens
Functions: grep sed xargs
0

recursive find and replace. important stuff are grep -Z and zargs -0 which add zero byte after file name so sed can work even with file names with spaces.