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

May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!
Hide

Top Tags

Hide

Functions

All commands from sorted by
Terminal - All commands - 12,341 results
echo sortmeplease | grep -o . | sort | tr -d '\n'; echo
2009-09-03 00:52:49
User: MrMerry
Functions: echo grep sort tr
1

Sorts a character string, using common shell commands.

echo "5 k 3 5 / p" | dc
2009-09-03 00:21:54
User: xamaco
Functions: echo
2

using bc is for sissies. dc is much better :-D

Polish notation will rule the world...

find ~/Library/Application\ Support/Firefox/ -type f -name "*.sqlite" -exec sqlite3 {} VACUUM \;
nmap -R -sL 209.85.229.99/27 | awk '{if($3=="not")print"("$2") no PTR";else print$3" is "$2}' | grep '('
2009-09-02 16:33:15
User: netsaint
Functions: awk grep
Tags: nmap dns
4

This command uses nmap to perform reverse DNS lookups on a subnet. It produces a list of IP addresses with the corresponding PTR record for a given subnet. You can enter the subnet in CDIR notation (i.e. /24 for a Class C)). You could add "--dns-servers x.x.x.x" after the "-sL" if you need the lookups to be performed on a specific DNS server.

On some installations nmap needs sudo I believe. Also I hope awk is standard on most distros.

bc -l <<< s(3/5)
2009-09-02 15:41:39
User: akg240
Functions: bc
3

-l auto-selects many more digits (but you can round/truncate in your head, right) plus it loads a few math functions like sin().

awk '/d.[0-9]/{print $4}' /proc/partitions
2009-09-02 15:26:03
User: akg240
Functions: awk
3

Only one command and not dependant on full read access to the devices.

fdisk -l |grep -e '^/' |awk '{print $1}'|sed -e "s|/dev/||g"
cal -y
2009-09-02 12:57:23
User: andrepuel
Functions: cal
-1

Show today date on a yearly calendar.

free -m | awk '/Swap/ {print $4}'
2009-09-02 11:46:17
User: voyeg3r
Functions: awk free
-2

simple way to show free swap

free -b | grep "Swap:" | sed 's/ * / /g' | cut -d ' ' -f2
$php_dir/bin/php -i | grep configure
find ~/.mozilla/firefox/ -type f -name "*.sqlite" -exec sqlite3 {} VACUUM \;
for dnsREC in $(curl -s http://www.iana.org/assignments/dns-parameters |grep -Eo ^[A-Z\.]+\ |sed 's/TYPE//'); do echo -n "$dnsREC " && dig +short $dnsREC IANA.ORG; done
sudo grub-install --recheck /dev/sda1
grep -lir "sometext" * > sometext_found_in.log
2009-08-31 23:48:45
User: shaiss
Functions: grep
Tags: find text
1

I find this format easier to read if your going through lots of files. This way you can open the file in any editor and easily review the file

cut -f N- file.dat
strace <name of the program>
awk '{print substr($0, index($0,$N))}'
2009-08-31 19:47:10
User: mstoecker
Functions: awk
0

This command will print all fields from the given input to the end of each line, starting with the Nth field.

touch /tmp/file ; $EXECUTECOMMAND ; find /path -newer /tmp/file
2009-08-31 18:47:19
User: matthewdavis
Functions: find touch
22

This has helped me numerous times trying to find either log files or tmp files that get created after execution of a command. And really eye opening as to how active a given process really is. Play around with -anewer, -cnewer & -newerXY

wget -nv http://en.wikipedia.org/wiki/Linux -O- | egrep -o "http://[^[:space:]]*.jpg" | xargs -P 10 -r -n 1 wget -nv
2009-08-31 18:37:33
User: syssyphus
Functions: egrep wget xargs
10

xargs can be used in this manner to download multiple files at a time, and xargs will in this case run 10 processes at a time and initiate a new one when the number running falls below 10.

dsh -M -c -f servers -- "command HERE"
2009-08-31 12:08:38
User: foob4r
Tags: ssh multiple
4

dsh - Distributed shell, or dancer?s shell ;-)

you can put your servers into /etc/dsh/machines.list than you don't have to serperate them by commata or group them in different files and only run commands for this groups

dsh -M -c -a -- "apt-get update"

scutil --dns
B <<< $(A)
yum --nogpgcheck install "examplePackage"
2009-08-30 18:18:30
User: iDen
Functions: install
-1

Same as:

1 rpm -ivh package.rpm

2 yum localinstall package.rpm

3 Edit /etc/yum.conf or repository.repo and change the value of gpgcheck from 1 to 0 (!dangerous)

awk '{print $1}' /var/log/httpd/access_log | sort | uniq -c | sort -rnk1 | head -n 10