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,925 results
gconftool-2 --set /apps/metacity/global_keybindings/panel_main_menu --type string "Super_L"
synclient TouchPadOff=1
synclient TouchPadOff=0
grep 'HOME.*' data.txt | awk '{print $2}' | awk '{FS="/"}{print $NF}' OR USE ALTERNATE WAY awk '/HOME/ {print $2}' data.txt | awk -F'/' '{print $NF}'
2009-03-05 07:28:26
User: rommelsharma
Functions: awk grep
-3

grep 'HOME.*' data.txt | awk '{print $2}' | awk '{FS="/"}{print $NF}'

OR

awk '/HOME/ {print $2}' data.txt | awk -F'/' '{print $NF}'

In this example, we are having a text file that is having several entries like:

---

c1 c2 c3 c4

this is some data

HOME /dir1/dir2/.../dirN/somefile1.xml

HOME /dir1/dir2/somefile2.xml

some more data

---

for lines starting with HOME, we are extracting the second field that is a 'file path with file name', and from that we need to get the filename only and ignore the slash delimited path.

The output would be:

somefile1.xml

somefile2.xml

(In case you give a -ive - pls give the reasons as well and enlighten the souls :-) )

cd !$
2009-05-08 09:48:14
Functions: cd
-3

During this operation :

# mv Joomla_1.5.10-Stable-Full_Package.zip /var/www/joomla/

I invoke /var/www/joomla/ as last command argument. To change in this directory I can use

# cd !$

So I go to

hob:/var/www/joomla#

gzip *
2010-03-29 10:58:40
User: funky
Functions: gzip
Tags: gzip
-3

Should do exactly the same - compress every file in the current directory. You can even use it recursively:

gzip -r .
tune2fs -l $(df -P / | tail -n1 | cut -d' ' -f1 ) | grep 'Filesystem created:'
sudo ls ; sudo gedit /etc/passwd &
2010-10-05 21:01:34
User: aporter
Functions: ls sudo
-3

Take advantage of sudo keeping you authenticated for ~15 minutes.

The command is a little longer, but it does not require X (it can run on a headless server).

list the naming contexts of a directory server (no need to search in config files)
pon dsl-provider
grep -r "mystring" . |uniq | cut -d: -f1 | xargs sed -i "s/mystring//"
2009-04-09 12:49:01
Functions: cut grep sed uniq xargs
-3

Linux : these script enable you to edit multiple files and remove exact phrase from multiple files

ls .[!.]*
2009-09-29 13:50:13
User: danam
Functions: ls
-3

Although rm is protected against it, there are many commands that would wreak havoc on entering the obvious ".*" to address "dot-files". This sweet little expression excludes the dirs "." and ".." that cause the problems.

for ((i=0;i<5;i++)) ; do xpenguins & done
netstat -ie
grep -sq "" /etc/lsb-release && lsb_release -rd
2009-02-17 05:21:20
User: int19h
Functions: grep
-3

grep -sq "" filename && command

grep can be used in combination with && to run a command if a file exists.

for i in $(seq 5); do xpenguins & done
for i in `ps -ef | grep tracker | awk '{print $8}' | cut -d'/' -f4 | grep -v grep`; do killall -9 $i; done
2011-12-04 13:20:19
User: alienone
Functions: awk cut grep killall
-3

* ps -ef # list running processes

* grep string

* pull the process names from 8th field

* cut and delimiter '/'

* print 4th field

* get rid of trailing grep

* for loop killall -9 $i which is the process name

bvi [binary-file]
2009-03-24 15:30:50
User: haivu
Tags: edit
-3

bvi is your vi for binary editing. If your system does not have it, you can get it from

http://bvi.sourceforge.net/

xmlstarlet sel --net -t -o "Terrorist threat level: " -v //@CONDITION http://is.gd/wacQtQ
host <domain> <nameserver name>
2009-09-29 18:58:28
User: DoGik
Functions: host
-3

Its very useful when you do not have control over name servers and need to check DNS configuration directly, right after change. You will not need to wait for DNS propagation to verify if all records were configured properly by vendors of name servers.

sudo /etc/acpi/sleep.sh sleep
2010-08-03 23:54:49
User: jmfork
Functions: sudo
Tags: sleep suspend
-3

It suspends to RAM: you always need your batteries for the RAM but it saves time as there is no need to slowly archive everything on your hard disk.

It works fine with me but if anyone has a nicer way, please contribute.

gpg -ab file.txt
gpg -ser 'myfriend@gmail.com' file.txt
2011-09-17 04:51:02
User: kev
Functions: gpg
Tags: GPG
-3

-s

Make a signature.

-e

Encrypt data.

-r

Encrypt for user id name.

curl sputnick-area.net/ua
2011-10-24 09:57:50
User: sputnick
Tags: curl headers
-3

That's useful when you're doing some web scraping http://en.wikipedia.org/wiki/Web_scraping and you're trying to test your possibly fake user-agent.

grep -H -r "string" ./* >> grep.txt