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.

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

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

All commands from sorted by
Terminal - All commands - 11,847 results
curl -s "https://www.random.org/cgi-bin/randbyte?nbytes=4" | od -DAn
2010-11-09 18:26:24
Functions: od
Tags: random
-1

Grab 4 bytes from www.random.org over ssl and format them as an integer

html2text http://checkip.dyndns.org | grep -i 'Current IP Address:'|cut -c21-36
tail -f LOGFILE | awk '{system("say \"" $0 "\"");}'
2011-09-16 06:20:06
User: tamouse
Functions: awk tail
Tags: awk tail say
-1

like #9295, but awkish instead of perlish

tar -cf "../${PWD##*/}.tar" .
2013-11-06 11:15:38
User: joedhon
Functions: tar
-1

should do the same as command #12875, just shorter.

cat schema.sql data.sql test_data.sql | mysql -u user --password=pass dbname
2009-03-24 08:39:40
User: tristan_ph
Functions: cat
Tags: mysql cat
-1

Be aware of using the --password argument as it will appear your password in plain text on the screen. You may use -p argument instead, it will prompt you to enter you password in hidden mode.

wget http://www.discogs.com/search?q=724349691704 -O foobar &> /dev/null ; grep \/release\/ foobar | head -2 | tail -1 | sed -e 's/^<div>.*>\(.*\)<\/a><\/div>/\1/' ; rm foobar
2011-01-30 23:34:54
User: TetsuyO
Functions: grep head rm sed tail wget
-1

Substitute that 724349691704 with an UPC of a CD you have at hand, and (hopefully) this oneliner should return the $Artist - $Title, querying discogs.com.

Yes, I know, all that head/tail/grep crap can be improved with a single sed command, feel free to send "patches" :D

Enjoy!

echo -n "String to MD5" | md5sum | awk '{print $1}'
(echo 0; find [args...] -printf '%s +\n'; echo p) | dc
2011-08-17 07:49:55
User: wipu
Functions: echo find
-1

Just an alternative. Here the output of the subshell statement is a complete script for dc so you can save it, manipulate it with some other tool or just debug it with less.

s=/etc/ssh/sshd_config;r=PermitRootLogin;cp $s{,.old}&& if grep $r $s;then sed "s/$r yes/$r no/" $s.old > $s; else echo $r no >> $s;fi
2011-01-30 23:41:59
User: kzh
Functions: cp echo grep sed
Tags: bash openssh
-1

This will tighten up security for your box. The default value for PermitRootLogin sadly is 'yes'.

mysql -u <user> --password=<password> -e "SHOW COLUMNS FROM <table>" <database> | awk '{print $1}' | tr "\n" "," | sed 's/,$//g'
2009-10-29 13:42:17
User: maxmanders
Functions: awk sed tr
-1

Useful when you need to write e.g. an INSERT for a table with a large number of columns. This command will retrieve the column names and comma-separate them ready for INSERT INTO(...), removing the last comma.

ffmpeg -i movie.mpg -vhook '/usr/lib/vhook/watermark.so -f overlay.png -m 1 -t 222222' -an mm.flv
fdupes DIRECTORY/ -r -d
2011-03-05 09:48:35
User: desmatron
-1

allow you to find duplicates files in "DIRECTORY" and choose wich one to delete

fudpes must be installed: sudo apt-get install fdupes

( while read File; do mogrify -resize 1024 -quality 96 $File; done ) < filelist
2009-02-08 02:48:26
User: Corsair
Functions: read
-1

Imagemagick library is used. If image format is not JPEG, the "quality" option should not be issued.

sudo service bluetooth restart
kill -9 $(ps -ef | grep [h]ttpd | awk '{print $2}')
echo -e "CHECK=SAMPLE" output --command_to_long
2013-04-03 08:46:47
User: techie
Functions: echo
-1

This is longer than others on here. The reason for this is I have combined two different matrix commands so it would work on all computers. I logged onto my server through a computer and it worked fine. I logged into my server through a mac and it looked $4!t so I have made one that works through both.

ps -e -o pid,vsz,comm= | sort -n -k 2
2014-05-14 00:36:50
Functions: ps sort
-1

left-most column is PID, middle is virtual memory being consumed, right-most is actual process.

find . -size 0 -print0 | xargs -0 rm
2009-10-29 14:10:02
User: osvaldofilho
Functions: find xargs
-1

The command find search commands with size zero and erase them.

date MMDDhhmmYYYY
2010-05-29 08:26:13
User: christian773
Functions: date
-1

date MMDDhhmmYYYY

date MMDDhhmm

# example 27.12.1975 08:00

date 122708001975

c="cp -a";e="~";echo -e "\npaste\n";i=0;k="1"; while [[ "$k" != "" ]]; do read -a k;r[i]=$k;((i++));done;i=0;while :;do t=${r[i]};[ "$t" == "" ] && break; g=$(echo $c ${r[i]} $e);echo -e $g "\ny/n?";read y;[ "$y" != "n" ] && eval $g;((i++));done
2011-12-04 12:45:44
User: knoppix5
Functions: echo eval read
-1

Schematics:

command [options] [paste your variable here] parameter

command [options] [paste entire column of variables here] parameter

...

(hard-code command "c" and parameter "e" according to your wishes: in example shown command = "cp -a" and parameter = "~")

Features:

- Quick exchange only variable part of a long command line

- Make variable part to be an entire column of data (i.e. file list)

- Full control while processing every single item

Hints:

Paste column of data from anywhere. I.e. utilize the Block Select Mode to drag, select and copy columns (In KDE Konsole with Ctrl+Alt pressed, or only Ctrl pressed in GNOME Terminal respectively).

Disadvantages:

You can paste only one single variable in a row. If there are more space separated variables in a row only first one will be processed, but you can arrange your variables in a column instead. To transpose rows to columns or vice versa look at Linux manual pages for 'cut' and 'paste'.

TODO:

- add edit mode to vary command "c" and parameter "e" on the fly

- add one edit mode more to handle every list item different

- add y/n/a (=All) instead of only y(=default)/n to allowed answers

Disclaimer:

The code is not optimized, only the basic idea is presented here. It's up to you to shorten code or extend the functionality.

kde-open -v | grep Platform | cut -d' ' -f4-
2012-01-19 13:05:26
User: funollet
Functions: cut grep
-1

Sample input:

kde-open -v

Qt: 4.7.4

KDE Development Platform: 4.7.3 (4.7.3)

KIO Client: 2.0

sed -i 's/http:\/\/old\/new\///g' index.html
tar -cf - folder/ | gpg -c > folder.tpg
2009-05-08 19:20:08
User: copremesis
Functions: gpg tar
-1

gpg's compression is as suitable as gzip's however your backups can now be encrypted.

to extract use:

gpg < folder.tpg | tar -xf -
fetch -q -o - http://ipchicken.com | egrep -o '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}'
2009-08-06 11:57:44
User: spackle
Functions: egrep
-1

Same thing as above, just uses fetch and ipchicken.com

disper --displays=auto -e -t left
2010-01-28 06:46:56
-1

Disper: http://willem.engen.nl/projects/disper/

Moving Gnome Panels to the external screen is done using gconf-editor, changing property "/apps/panel/toplevels/top_panel_screen0/monitor", as well as "/apps/panel/toplevels/bottom_panel_screen0/monitor" to int value "1". This can be done from the command line using '

gconftool-2 --set "/apps/panel/toplevels/top_panel_screen0/monitor" --type integer "1"' so a nice script can be written.