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,928 results
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.

xcopy /e/h/y /z/i /k /f src dest
2009-02-13 16:25:09
User: piyo
-3

I can remember "cp -av" on Unix like systems to copy files and directories. The same can be done on Windows without extra software, somewhat.

The switches mean:

/E Copies directories and subdirectories, including empty ones.

Same as /S /E. May be used to modify /T.

/H Copies hidden and system files also.

/Y Suppresses prompting to confirm you want to overwrite an

existing destination file.

/Z Copies networked files in restartable mode.

/I If destination does not exist and copying more than one file,

assumes that destination must be a directory.

/K Copies attributes. Normal Xcopy will reset read-only attributes.

/F Displays full source and destination file names while copying.

I don't type that all the time, I stick it into a file called "cpav.cmd" and run that.

echo xcopy /e/h/y /z/i /k /f %1 %2 > cpav.cmd cpav zsh zsh2

http://support.microsoft.com/kb/323007

dd if="\\?\Device\CdRom0" of=c:\temp\disc1.iso bs=1M --progress
2009-02-13 16:14:50
User: piyo
Functions: dd
-1

dd for windows is available from http://www.chrysocome.net/dd

Tested with CD-ROMs like Linux install discs

I don't know about DVD-ROMs.

cd /d d:\Windows
2009-02-13 16:06:48
User: piyo
Functions: cd
-2

In the Windows cmd.exe window, you can change the directory using cd, but if you need to go to a directory on another drive, you need to type in the drive letter and colon first (e.g. d:). With the /d on cd, you don't need this intermediate step.

cd /?

Tested on Windows XP

explorer /e,.
2009-02-13 16:00:19
User: piyo
-1

Sometimes I want to use the mouse to move/copy/delete files.

(I also sometimes feel like a nut, sometimes I don't.)

This is for Windows 2000 and later, probably.

Tested on Windows XP, cmd.exe.

http://support.microsoft.com/kb/130510

echo $PATH | tr : \\n
2009-02-13 15:54:58
User: piyo
Functions: echo tr
2

This works in bash and zsh.

You may also want to alias it, if you need to look at it often...

alias lpath="echo \$PATH | tr : \\\\n"

"\$PATH" to make sure to look at your current $PATH

sc queryex type= service state= all | find "_NAME"
2009-02-13 15:44:42
User: piyo
Functions: find
3

On Windows 2000 or later, this command will give a listing of all the registered Windows services. You can then know what the name of a command is in order to start and stop it.

e.g.

sc start Apache2.2

or

net start Apache2.2

Please note that sc will allow the SERVICE_NAME only, while net will allow both SERVICE_NAME and DISPLAY_NAME.

Note that the space between the = and the next word are important. Not very unixy, that.

http://www.ss64.com/nt/sc.html

http://www.ss64.com/nt/net_service.html

http://technet.microsoft.com/en-us/library/bb490995.aspx

find . -name '*.jar' -printf '%f:'
2009-02-13 15:37:51
User: yalestar
Functions: find
9

Useful for making a CLASSPATH out of a list of JAR files, for example.

Also:

export CLASSPATH=.:$(find ./lib -name '*.jar' -printf '%p:')

git config --global --add alias.ff "pull --no-commit -v" ; git ff
2009-02-13 15:30:46
User: piyo
1

This command will first add an alias known only to git, which will allow you to pull a remote and first-forward the current branch. However, if the remote/branch and your branch have diverged, it will stop before actually trying to merge the two, so you can back out the changes.

http://www.kernel.org/pub/software/scm/git/docs/git-pull.html

Tested on git 1.5.6.1, msysgit (Windows port)

Actually this is not really the way I want it. I want it to attempt a fast-foward, but not attempt to merge or change my working copy. Unfortunately git pull doesn't have that functionality (yet?).

cat SomeFile.txt | pbcopy
2009-02-13 15:23:10
Functions: cat
2

Great for little scripts that dig up obscure info that you are going to have to paste into another app anyway.

netsh interface ip dump > current-interfaces.txt
2009-02-13 15:13:05
User: piyo
Functions: dump
-2

On Windows 2000 or newer, you can use the command line to save the current network interface info.

You can then edit the text file and re-apply it using the netsh -f command (or netsh exec). Keep a bunch of text files around to quickly switch connection info without using extra software.

http://en.wikipedia.org/wiki/Netsh

http://support.microsoft.com/kb/242468

http://thelazyadmin.com/blogs/thelazyadmin/archive/2005/04/04/Using-Netsh-to-Manage-Network-Interfaces-Part-2.aspx

ifconfig eth0 | awk '/inet addr/ {split ($2,A,":"); print A[2]}'
update-alternatives --config x-terminal-emulator
date +%s
2009-02-13 13:30:44
User: legba7
Functions: date
4

displays time in seconds since January 1, 1970 UTC

sleep 3m; play bigben.wav
2009-02-13 13:20:13
User: legba7
Functions: sleep
0

plays wave file after 3 minutes