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,617 results
cat welcome | wall
2009-02-14 18:12:50
User: Williebee
Functions: cat
-3

Show message in file "welcome" to all logged in terminal users.

touch <filename>
> filename
alias rk='d=$(dcop|grep $PPID) && s=$(dcop $d konsole currentSession) && dcop $d $s renameSession'
2009-02-14 00:02:43
User: wwest4
Functions: alias
1

usage: renam

in a script you must replace $PPID with $(awk '{print $4}' /prod/$PPID/stat)

git config --global alias.log1 "log --pretty=oneline --abbrev-commit"
2009-02-13 23:38:42
User: bartman
0

This command limits the oputut of git log to one-line per commit and an abbreviated commit ID.

find -printf '%u %g\n' | sort | uniq
2009-02-13 22:42:49
User: leper421
Functions: find sort
8

find -printf '%u\n' | sort | uniq #just users

find -printf '%g\n' | sort | uniq #just groups

PS1='$PWD$ '
2009-02-13 22:00:57
User: Aldiansblog
-2

If you have tried to change your prompt and made a mistake, use this command to retrieve a standard prompt.

If you used the export command when you changed your prompt, also use it there:

export PS1='$PWD$ '

gconftool-2 --set "/system/http_proxy/use_http_proxy" --type boolean true
2009-02-13 22:00:52
User: Kysic
0

Solution to activate (or deactivate with false instead of true) the global mandatory proxy under Ubuntu (not tested elsewhere).

Others keys you can configure :

gconftool-2 --set "/system/http_proxy/host" --type string "

gconftool-2 --set "/system/http_proxy/port" --type int 8080

gconftool-2 --set "/system/http_proxy/ignore_hosts" --type list --list-type string ["localhost","127.0.0.1","*.local"]

gconftool-2 --set "/system/proxy/mode" --type string manual

PS1='$'
2009-02-13 21:58:42
User: Aldiansblog
-1

When you need to work a long time in the same directory, which prompt is of the type:

bob@ubuntu:~/directory1/directory2/directory3/directory4/directory5$

it is better to hide all this with the command PS1='$'

To retrieve a normal prompt, type: PS1='$PWD$ '

while [ 0 ]; do expr 2365200000 \- `date +%s` \- `date --date "YYYY-mm-dd HH:MM:ss" +%s`; sleep 1; clear; done
2009-02-13 20:02:37
User: wwest4
Functions: expr sleep
1

watch the seconds of your life tick away - replace YYYY-mm-dd HH:MM:ss w/ your birthtime.

export PS1='\[\e]0;\h \u \w\a\]\n\[\e[0;34m\]\u@\h \[\e[33m\]\w\[\e[0;32m\]\n\$ '
2009-02-13 19:49:17
User: OS2
Functions: export
1

used in an if-then-else in case the default shell is ksh, not bash.

The $(basename ${0#-}) is handy to echo which shell and strip the dash some flavors put in front of "bash"

if [ $(basename ${0#-}) == "bash" ] ; then

export PS1='\[\e]0;\h \u \w\a\]\n\[\e[0;34m\]\u@\h \[\e[33m\]\w\[\e[0;32m\]\n\$ '

else

HOST=`hostname`

ESC=`echo "\033"`

BEL=`echo "\007"`

RAW=`echo "\r"`

export PS1='-${RAW}${ESC}]0;${HOST} ${USER}${BEL}-${ESC}[0;34m${USER}${ESC}[0m@${ESC}[0;34m${HOST%%.*}${ESC}[0;33m${ESC}[0m $ '

fi

echo $(( (1234567890 - `date -u +\%s`) / 60 / 60 ))
sudo apt-get install preload
2009-02-13 19:34:57
User: danfernbanck
Functions: install sudo
-7

this application monitors the apps you use most often and load them into memory with their libraries and other dependencies.

So now, when you launch Firefox or Thunderbird or OpenOffice, the display is immediate as on Mac.

ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o ",k);print}'
2009-02-13 19:20:54
User: iArno
Functions: awk ls
6

Do ls with permissions written in octal form.

wget -p --convert-links http://www.foo.com
2009-02-13 19:02:08
User: damniel
Functions: wget
8

The example will create a directory called "

Caveats: @imports of css files will not be converted.

kill -9 $(pidof *program*)
date -R -d @1234567890
sed -e "/$USER/d;s/:.*//g" /etc/group | sed -e :a -e '/$/N;s/\n/ /;ta'
sed -e :a -e '/$/N;s/\n/ /;ta' <filename>
htpdate -P proxy www.google.com www.yahoo.com www.commandlinefu.com
2009-02-13 17:31:11
User: piyo
-2

HTP (HTTP Time Protocol) is an alternative way of getting "good enough" synchronized time. htpdate will give you near-second accuracy.

It works where NTP/SNTP does not because of firewalls and proxies. Of course, if NTP/SNTP can be used, use that instead.

http://www.clevervest.com/twiki/bin/view/HTP

htp is not in Ubuntu!

startx -- :1
2009-02-13 17:22:13
User: sudo
-1

Just tape:

sudo -s

your passwd

startx -- :1

watch ccache -s
2009-02-13 17:16:32
User: piyo
Functions: watch
-1

OMG, you are a Gentoo junkie.

-funroll-loops-me-harder ;-)

http://ccache.samba.org/

ccache is a compiler cache, which speeds up your compiler on successive runs, because it caches intermediate compiled output.

dpkg --list '*linux*' | grep '^ii'
2009-02-13 17:05:37
User: piyo
Functions: grep
1

I sometimes want to know what packages are installed on my Ubuntu system. I still haven't figured out how to use aptitude effectively, so this is the next best thing. This allows finding by name.

The grep '^ii' limits the display to only installed packages. If this is not specified, then it includes listing of non-installed packages as well.

gmake runtestsingle testsingle=udtime
2009-02-13 16:53:26
User: piyo
-1

Given a GNU Make file version 3.81 with the following entries:

.PHONY: runtest

runtest: $(ARCHNAME) $(TESTAUTOEXES)

@for i in $(TESTAUTOEXES) ; do \

echo ">>>> Running test harness $$i" ; \

env $(RUNTESTENV) $$i ; done

.PHONY: runtestsingle

runtestsingle: $(ARCHNAME)/test/auto_$(testsingle).exe $(ARCHNAME)

@for i in $< ; do \

echo ">>>> Running test harness $$i" ; \

env $(RUNTESTENV) $$i ; done

(ARCHNAME is something like ix86-linux-gnu)

Instead of typing gmake runtest to run all the tests, you can run one specific test with the example command.

The sample output is from compiling a C++ program using Boost::Test testing framework.

iptables -t nat -A OUTPUT -d ! 10.0.0.0/8 -p tcp --dport 80 -j DNAT --to-destination 10.1.1.123:3128
2009-02-13 16:40:31
User: ender_x
Functions: iptables
4

Replace 10.0.0.0/8 with your largest local subnet. replace 10.1.1.123:3128 with your proxy information.. Note this only works with a proxy server configured for passive setup..

Now your firefox transparently proxy's stuff destined outside your network.. and Doesn't proxy stuff inside your network. as well as all your other favorite web applications. curl, wget, aria2 ect.