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

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 - 12,034 results
kill %1
ls .??*
2009-09-29 14:40:37
User: Paula
Functions: ls
-5

Works 99.9% of the time; so far never required a more complex expression in manual input.

curl -u username --silent "https://mail.google.com/mail/feed/atom" | perl -ne 'print "\t" if /<name>/; print "$2\n" if /<(title|name)>(.*)<\/\1>/;
2009-09-09 23:25:05
User: suxer
Functions: perl
-5

notice what happens when there is more than one unread message in a thread...

also people please dont hardcode the password when you use curl. Leave it out and curl will ask you when it runs. Please...?

sudo service vpnclient_init start
2010-11-10 20:18:08
User: mariusbutuc
Functions: sudo
Tags: VPN CISCO
-5

Prerequisites:

[1] download the CISCO VPN client for linux: http://tuxx-home.at/archives/2007/09/24/T15_26_49/

[2] apply this ciscpo VPN patch: http://bit.ly/linux_vpn_patch

[*] use command to start client

[*+1] After copying your profile file to /etc/opt/cisco-vpnclient/Profiles, connect using

vpnclient connect TORVPN-TCP
egrep -in "this|that" *.dat
2011-07-06 09:42:26
User: evandrix
Functions: egrep
-5

grep - Search file for character string

Search for one or more strings in one or more files. Examples:-

grep that myfile.txt

Look for the string ``that'' in the file called ``myfile.txt'' and print out each line that matches.

egrep -in "this|that" *.dat

Extended grep search *.dat files for ``this'' or ``that'' case insensitive (-i) and where found print line number (-n) along with the line contents.

find . -name "*~" -exec rm {} \;
2010-02-26 10:54:02
User: ivanatora
Functions: find rm
Tags: vim find
-5

Assuming only VIM has *~ files in your current dir. If you have usefull data in a file named in the *~ pattern, DO NOT RUN this command!

fdisk -l /dev/sda
ps aux | awk '/name/ {print $2}'
2009-02-20 21:35:52
User: evil_otto
Functions: awk ps
-5

This finds a process id by name, but without the extra grep that you usually see. Remember, awk can grep too!

cd //
find ~ -mtime +365 -exec mv {} /tmp/mybackup \;
2009-04-11 12:16:48
User: kayowas
Functions: find mv
-5

This example uses the -exec option to move all matching files into a backup directory

perl -e 'map { $on=$_; s/\]/_/; rename($on, $_) or warn $!; } <*>;'
gcc -x c -o /tmp/out - -lgmp <<< '#include <stdlib.h> ... SEE SAMPLE OUTPUT FOR FULL COMMAND
2009-09-10 02:10:46
User: hank
Functions: c++ gcc
-5

It's hard to beat C. This is just slightly faster than the bc version on my machine.

real 0m26.856s

user 0m25.030s

sys 0m0.024s

Requirements: libgmp headers, gcc.

ps ax | grep <processname> | grep -v grep | awk '{print $1}' | sudo xargs kill -9
dd if=/dev/zero of=/dev/hda
for i in `netstat -rn |grep lan |cut -c55-60 |sort |uniq`; do ifconfig $i; done
2010-01-28 17:35:20
User: Kaio
Functions: cut grep ifconfig sort
-5

HP UX doesn't have a -a switch in the ifconfig command.

This line emulates the same result shown in Solaris, AIX or Linux

alias pfind='ps aux | grep '
$ lynx -useragent=Opera -dump 'http://www.facebook.com/ajax/typeahead_friends.php?u=100003119823986&__a=1' |gawk -F'\"t\":\"' -v RS='\",' 'RT{print $NF}' |grep -v '\"n\":\"' |cut -d, -f2
dd if=/dev/urandom of=/dev/somedisk
2012-01-24 09:13:15
User: joedhon
Functions: dd
-5

Same game as #10096 . loop as many times as you like.

cat > /dev/null
2010-10-08 14:35:25
User: GouNiNi
Functions: cat
-5

In exemple, screen can bind keys to switch between windows. I like to use Ctrl + Arrow to move left or right window. So I bind like this in .screenrc :

bindkey ^[OD prev # Ctl-left, prev window

bindkey ^[OC next # Ctl-right, next window

rpm -qf /lib/modules/*
2010-03-01 05:00:56
User: megacoder
Functions: rpm
-5

Exploit that RPM database just sitting there, taking up space.

while read line; do echo $line; done <<< "$var"
2011-09-22 16:53:32
User: totti
Functions: echo read
-5

Consider the following simple situation [ reading something using while and read ]

[See script 1 in sample output]

---------------------------------------------------

The variable var is assigned with "nullll" at first. Inside the while loop [piped while] it is assigned with "whillleeee". [Onlly 2 assignments stmts]. Outside the loop the last assigned value for "var" [and no variable] inside the while can't be accessed [Due to pipe, var is executed in a sub shell].

In these type of situation variables can be accessed by modifying as follows.

[See script 2 in sample output]

___________________________

Vary helpful when reading a set of items, say file names, stored on a file [or variable] to an array an use it later.

Is there any other way 2 access variables inside and outside the loop ??

while true; do sleep 4 ; xdotool click 1 ; done
2011-09-23 09:23:02
User: rusino
Functions: sleep
-5

Automation click every 4 second on a macro slot bar to world of warcraft for prospecting item

enable auto loot and create macro, put mouse over slot on the bar

/cast Prospecting

/use Elementium Ore

history -r
poweriso convert image.daa -o image.iso -ot iso