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.

Universal configuration monitoring and system of record for IT.
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

May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!
Hide

Top Tags

Hide

Functions

Hide

Credits

All commands from sorted by
Terminal - All commands - 12,159 results
now=`date +"%Y/%m/%d" -d "04/02/2005"` ; end=`date +"%Y/%m/%d" -d "07/31/2005"`; while [ "$now" != "$end" ] ; do now=`date +"%Y/%m/%d" -d "$now + 1 day"`; echo "$now"; done
sed -i 's/`head -n 500 foo.log`//' foo.log
2011-05-23 09:41:35
User: kevinquinnyo
Functions: sed
-1

This is good for cleaning up log files without having to erase the entire contents of the file, and allows you to keep the most recent entries to the log only

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'

grep -nrHi generate.*sh .i3/
2015-07-28 16:22:55
User: deterenkelt
Functions: grep
-1

Performs a case-insensitive (-i) recursive search (-r) and prints not only the match, but also the filename (-H) in which the match was found and corresponding line number (-n). All this is highlighted with different colours.

Requires GNU grep (v.2.21 was used for this example)

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.

brew update && brew upgrade
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