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,848 results
wget ifconfig.me/ip -q -O -
msgfilter --keep-header -i input.po -o empty.po awk -e '{}'
2012-01-14 13:29:26
User: unhammer
Functions: awk
-1

basically create a .pot file from a po-file, ready for translating

FLOOR=0; RANGE=10; number=0; while [ "$number" -le $FLOOR ]; do number=$RANDOM; let "number %= $RANGE"; done; echo $number
2009-02-20 09:33:56
User: raphink
Functions: echo
Tags: bash
-1

This one-liner outputs a random number between the values given for FLOOR and RANGE.

getdji (){local url sedcmd;url='http://finance.yahoo.com/q?d=t&s=^DJI';sedcmd='/(DJI:.*)/,/Day.*/!d;s/^ *//g;';sedcmd="$sedcmd/Change:/s/Down / -/;/Change:/s/Up / +/;";sedcmd="$sedcmd/Open:/s//& /";lynx -dump "$url" | sed "$sedcmd"; }
find . -iname '*TODO*'
find ./ $1 -name "* *" | while read a ; do mv "${a}" "${a//\ /_}" ; done
for vm in `/usr/bin/vmware-cmd -l`; do /usr/bin/vmware-cmd "${vm}" stop trysoft; done
2011-09-15 06:56:49
User: maxheadroom
-1

This command will shutdown all VMs on an VMWare ESX host. First it tries to gracefully shutdown the VM. If that fails it will hard shutdown and the power off.

su <username>
which somecommand
2009-02-05 10:29:04
User: chrisdrew
Functions: which
-1

Returns the pathnames of the files which would be executed in the current environment had its arguments been given as a command.

cat file-that-failed-to-download.zip | curl -C - http://www.somewhere.com/file-I-want-to-download.zip >successfully-downloaded.zip
2009-08-05 13:33:06
Functions: cat
-1

If you are downloading a big file (or even a small one) and the connection breaks or times out, use this command in order to RESUME the download where it failed, instead of having to start downloading from the beginning. This is a real win for downloading debian ISO images over a buggy DSL modem.

Take the partially downloaded file and cat it into the STDIN of curl, as shown. Then use the "-C -" option followed by the URL of the file you were originally downloading.

{ u="http://twitter.com/commandlinefu"; echo "Subject: $u"; echo "Mime-Version: 1.0"; echo -e "Content-Type: text/html; charset=utf-8\n\n"; curl $u ; } | sendmail recipient@example.com
2010-02-24 04:18:30
User: pascalv
Functions: echo sendmail
-1

This will send the web page at $u to recipient@example.com . To send the web page to oneself, recipient@example.com can be replaced by $(whoami) .

The "charset" is UTF-8 here, but any alternative charset of your choice would work.

`wget -O - -o /dev/null $u` may be considered instead of `curl $u` .

On some systems the complete path to sendmail may be necessary, for instance /sys/pkg/libexec/sendmail/sendmail for some NetBSD.

export PSOA='user,pid,time,state,command' ; function _ps { /bin/ps $@ ; } ; alias psa='_ps ax -o $PSOA'
2010-05-27 02:07:56
User: mattmartini
Functions: alias export
-1

#ps aliases

PSO='user,pid,ppid,%cpu,%mem,time,start,state,command'

PSOA='user,pid,time,state,command'

PSOL='user,pid,ppid,%cpu,%mem,nice,pri,etime,time,tt,state,ucomm'

export PSO PSOA PSOL

function _ps { /bin/ps $@ ; }

alias ps='_ps ax -o $PSO'

alias psa='_ps ax -o $PSOA'

alias psl='_ps ax -o $PSOL'

alias psm='_ps -U $USER -o $PSOA'

svn log . --stop-on-copy
2010-02-24 12:37:18
User: reaper
-1

The command show the log of a branch, stopping the output at the time of branch creation.

xterm +u8 -fn mtx -maximized -T "There is no spoon!" -e cmatrix -bxa -u 3 & sleep .1s && wmctrl -r :ACTIVE: -b add,fullscreen && transset-df -a &
2012-09-28 04:46:28
User: bugmenot
Functions: sleep
-1
apt-get install cmatrix cmatrix-xfont wmctrl transset-df

Need to restart computer for mtx font to work

Commands while cmatrix is running:

1 - 9 = Change speed

SHIFT + 1 - 7 = change colors

Q = Quit

Tested in Ubuntu 10.04

twistd -no web
2014-02-01 22:35:50
User: nkorth
-1

Install twistd first with

sudo apt-get install python-twistd-web
cd /usr/ports; grep -F "`for o in \`pkg_info -qao\` ; \ do echo "|/usr/ports/${o}|" ; done`" `make -V INDEXFILE` | \ grep -i \|ports@freebsd.org\| | cut -f 2 -d \|
2009-02-16 21:07:35
User: grep
Functions: cd cut grep
-1

only works for freeBSD where ports are installed in /usr/ports

credit to http://wiki.freebsd.org/PortsTasks

CTRL + a
export PS1='\D{%a %D %T}> '
cd -
2011-07-05 05:28:32
Functions: cd
-1

Add dirs to list:

pushd /tmp

/tmp ~

then

cd -

/home/user

cd -

/tmp

RANGE=`wc -l /usr/share/dict/words | sed 's/^\([0-9]*\) .*$/\1/'`; for i in {1..4}; do let "N = $RANDOM % $RANGE"; sed -n -e "${N}p" /usr/share/dict/words | tr -d '\n'; done; RANGE=100; let "N = $RANDOM % $RANGE"; echo $N
while :; do cat file.txt | nc -l 80; done
vim -c'highlight Comment ctermfg=white' my.conf
2011-10-21 00:53:03
User: kev
Functions: vim
Tags: vim
-1

you should choose proper color to make comments invisible.

Boot up destination machine with Knoppix live CD and run nc -l -p 9000 | dd of=/dev/sda Then on the master dd if=/dev/sda | nc <dest-ip> 9000 You can monitor bandwidth usage to see progress: nload eth0 -u M
2009-05-07 05:26:58
User: lv4tech
Functions: dd
-1

This is a bit to bit copy so if you have a 500GB hard disk it will take a long time even if have Gigabit Ethernet

printf "%s\n" !(pattern) ## ksh, or bash with shopt -s extglob
2009-11-26 14:09:56
User: cfajohnson
Functions: bash printf
Tags: ls grep
-1

There's no need for ls or grep; printf is builtin to most modern shells

echo "Terrorist threat level: `sed $(perl -e "print int rand(99999)")"q;d" /usr/share/dict/words`"
2011-01-28 09:49:37
User: houghi
Functions: echo
-1

Numbers are less understandable then words. Also this may put out a different result.