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.


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

Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

All commands from sorted by
Terminal - All commands - 12,403 results
egrep '183\.([0-9]|(1[0-6]|2[0-3]))' -J /var/log/maillog*
2010-10-17 21:44:57
User: wazigster
Functions: egrep
0

Useful for grepping an IP range from the maillog. When for instance dealing with a spam-run from a specific IP range, or when errors occur from or to a specific IP-range.

In the example above the IP range 183.0.0.0/10 (183.0.0.0 - 183.63.255.255)

To grep the IP range 124.217.224.0/19 (124.217.224.0 - 124.217.255.255) from the maillog:

egrep '124\.217\.2(2[4-9]|[34][0-9]|5[0-5])' -J /var/log/maillog*

NOTE: the location of the maillog may vary based upon operating system and distribution.

awk '/^'$SEARCH'[ ]*$/{getline;if ($1 ~ /query/) {split($4,a,".");print a[2]}}' /etc/sybase/interfaces
2010-12-17 13:24:27
User: JohnGH
Functions: awk
0

Awk magic to replace:

cat /etc/sybase/interfaces | grep -A 1 -e "$SEARCH" | grep query | awk '{ print $4 }' | awk -F'.' '{print $2}'

( for((i=0;$i<100;i++))do echo volume $i 1; sleep 0.1s; done; )| mplayer -slave -quiet sample.mp3
2011-01-06 11:22:03
User: Juluan
Functions: echo sleep
0

Of course, a fifo is required for piloting the fade out of another song, but with a few bash function, we can mix music in bash like :

crossfadeIn > mplayerfifo1 & crossfadeOut > mplayerfifo2

loop 0 10 > mplayer fifo1

etc etc

ping -a IP-ADDRESS
2011-04-28 13:51:12
User: markussesser
Functions: ping
0

pcspkr have to be enabled!

modprobe pcspkr

xset b on

get_duration () { IFS=.: read -r _ h m s _ < <(ffmpeg -i "$1" 2>&1 | grep Duration);echo $(( h * 3600 + m * 60 + s )); }
inxi -F
stat /etc/my.cnf
# ping -c 1000 -i 0.001 <host>
rsync -arl --rsh=ssh --progress --exclude-from=/etc/localbin/exclude_files.txt /var/www/html/source/* <user>@<server>:/var/www/html/source/
echo 'Etc/UTC' | tee /etc/timezone; dpkg-reconfigure --frontend noninteractive tzdata
2013-04-22 06:14:55
User: donatello
Functions: echo tee
0

Replace the first part of the command above with the appropriate timezone string. Eg: 'Europe/London' or for UTC - 'Etc/UTC'. The appropriate string can be found from https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

This is useful when your server is installed by a data centre (managed hardware, VPS, etc) and the timezone is not usually set to the one your prefer.

for y in {2009..2013}; do cal $y; done
fbcmd FSTATUS =all
perldoc -m Some::Module
wakeonlan 00:00:DE:AD:BE:EF
2014-06-13 16:16:33
User: tyzbit
0

Wakes up a computer on your LAN with a Wake-On-LAN packet. MAC Address must match the NIC MAC, computer must have WOL enabled in the BIOS.

eog someimg.jpg
grep page.php /var/log/httpd/access_log|awk '{print $1}'|sort|uniq|perl -e 'while (<STDIN>){chomp; $cmd=`ipset add banned -! -q $_`; }'
sudo security delete-certificate -c 1000-sans.badssl.com
2017-04-06 01:40:04
User: lgarron
Functions: sudo
0

Use `security list-keychains` to find possible keychains, and `security dump-keychain` to look for certificates.

`sudo security delete-certificate` without arguments shows options for removing: by common name or by SHA-1 hash.

This is especially useful if a certificate locks up Keychain Access.app, which happens for certificates with many SANs in macOS 10.12.

Found via: http://stackoverflow.com/a/16019443

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.

watch -d "free -mt"
on="off"; off="on"; now=$(amixer get Master | tr -d '[]' | grep "Playback.*%" |head -n1 |awk '{print $7}'); amixer sset Master ${!now}
i=0; for f in $(find ./ -size -10M -exec stat -c %s {} \; ); do i=$(($i + $f)); done; echo $i
tcpdump -i eth0 "tcp port pop3 and ip[40] = 85 and ip[41] = 83" -s 1500 -n -w "sniff"
2010-11-18 09:03:08
User: ironmarc
Functions: tcpdump
0

The command is useful for monitoring the use of the boxes and their connection IP.

Result file "sniff" is readable with GUI program "wireshark" or through CLI with the command:

tcpdump -f "sniff" -XX

shopt -s nullglob; for i in $(find "Your/file/system" -name "*.pdf"); do e="$(dirname $i)/$(basename $i '.pdf').png"; gs -sDEVICE=png16m -q -dPDFFitPage -g492x380 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dNOSUBSTDEVICECOLORS -o $e $i; done
2010-12-17 13:30:54
Functions: find gs
0

Using ghostscript instead of imagemagick to convert pdfs into pngs. It keeps pngs with pdfs

find src/ -name "*.java" | while read f; do echo -n "$f "; cat "$f" | tr -dc '{}'; echo; done | awk '{ print length($2), $1 }' | sort -n
sed ':a;N;$!ba;s/\n\n/\n%\n/g' input.txt >output