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,621 results
runas /user:administrator net stop wuauserv
2009-06-30 09:29:03
User: oernii2
4

Windows only: stops windows update and the nagging restart window.

You need your admin password for this one.

source ~/.bash_profile
2009-06-29 19:26:43
-6

when editing .bash_profile (or .bashrc), run this to use the new version without having to exit and open a new terminal

cat myfile.txt | tr -d '\n'
svn log | tr -d '\n' | sed -r 's/-{2,}/\n/g' | sed -r 's/ \([^\)]+\)//g' | sed -r 's/^r//' | sed -r "s/[0-9]+ lines?//g" | sort -g
2009-06-29 12:48:30
User: Cowboy
Functions: sed sort tr
3

Note you have also the --xml option ;)

? () { echo "$*" | bc -l; }
2009-06-28 20:15:30
User: fizz
Functions: bc echo
56

defines a handy function for quick calculations from cli.

once defined:

? 10*2+3
for i in *;do mv "$i" "$(echo $i | sed s/PROBLEM/FIX/g)";done
2009-06-28 01:50:25
User: AlecSchueler
Functions: mv
3

Useful if non-ascii characters in filenames have been improperly encoded. Replace "PROBLEM" with the incorrect characters (e.g. 'é'), and "FIX" with the correct ones (e.g. '?').

rename 'y/ /_/' *
2009-06-27 22:20:47
User: signal9
Functions: rename
Tags: file rename
48

This command will replace all the spaces in all the filenames of the current directory with underscores. There are other commands that do this here, but this one is the easiest and shortest.

curl -u YourUsername:YourPassword -d status="Your status message go here" http://twitter.com/statuses/update.xml
2009-06-27 21:47:48
User: m33600
Tags: twitter
2

Found it on snipt, pok3, is it yours?

I put my user = m33600, the password and the status was my robot message:

Settima robot message: ALARM ZONE 3 (sent via command line).

Now bots may have their identity on twitter...

S=`pidof skype`;grep heap /proc/$S/maps|cut -f1 -d' '|awk -F- '{print "0x" $1 " 0x" $2}'|xargs echo "du me t ">l;gdb -batch -p $S -x l>/dev/null 2>&1;strings t|grep \(smirk|head -n1
2009-06-26 20:03:17
User: alvieboy
Functions: awk cut echo grep head xargs
0

Skype has an internal regex which depicts the emoticons it supports. However you cannot simply search the binary file for it. This small 181 character line will do just that, provided skype is running. And of course, only works in linux.

awk '/regex/{print x};{x=$0}'
2009-06-26 19:29:54
User: res0nat0r
Functions: awk
4

Use this if you don't have access to GNU grep's -B option.

:let i=0 | 'a,'bg/ZZZZ/s/ZZZZ/\=i/ | let i=i+1
( cd SOURCEDIR && tar cf - . ) | (cd DESTDIR && tar xvpf - )
pax -r -s ',^/,,' -f file.tar
2009-06-26 19:10:57
User: res0nat0r
Functions: pax
Tags: tar
0

Don't have GNU tar installed that supports the redirect option (-C)? Use this.

find -L /proc/*/fd -links 0 2>/dev/null
2009-06-26 18:42:51
User: res0nat0r
Functions: find
Tags: du proc df
12

Oracle DBA remove some logfiles which are still open by the database and he is complaining the space has not been reclaimed? Use the above command to find out what PID needs to be stopped. Or alternatively recover the file via:

cp /proc/pid/fd/filehandle /new/file.txt
rsop.msc
2009-06-26 11:19:50
User: felix001
4

Type this into windows via run and it will display to you your complete policy for windows. This includes group policy, security policy and your active directory account (min password etc)....

www.fir3net.com

watch 'netstat -aniv'
netstat -lnp
ps aux | grep -v `whoami`
pdftk $* cat output $merged.pdf
echo "Hello World." | tee -a hello.txt
2009-06-26 00:55:59
Functions: echo tee
Tags: tee
1

When plumbers use pipes, they sometimes need a T-joint. The Unix equivalent to this is 'tee'. The -a flag tells 'tee' to append to the file, rather than clobbering it.

Tested on bash and tcsh.

man fetchmail | perl -ne 'undef $/; print $1 if m/^.*?(-k \| --keep.*)-K \| --nokeep.*$/smg'
2009-06-25 23:51:35
Functions: fetchmail man perl
0

Using perl, here, we grep the man page of fetchmail to find the paragraph starting with '-k | --keep' and ending before the paragraph starting with '-K | --nokeep'

echo "aplay path/to/song" |at [time]
2009-06-25 19:33:37
User: brausen
Functions: at echo
Tags: alarm
8

Set an alarm to starts in specific time.

sleep 5h && rhythmbox path/to/song
2009-06-25 19:15:19
User: becomingGuru
Functions: sleep
3

Sleep 5h and plays the song as a wake up alarm

gs -q -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=out.pdf a.pdf b.pdf c.pdf
2009-06-25 19:04:28
User: becomingGuru
Functions: gs
5

merge a.pdf b.pdf and c.pdf and create ./out.pdf

su - <user> -s /bin/sh -c "/bin/sh"