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.

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:



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!

Top Tags



All commands from sorted by
Terminal - All commands - 12,296 results
function verifyIP() { octet="(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])"; ip4="^$octet\.$octet\.$octet\.$octet$"; [[ ${1} =~ $ip4 ]] && return 0 || return 1; }
2015-05-01 12:22:57
User: mpb
Functions: return

When processing IP addresses in the shell (or shell script) it is useful to be able to verify that the value of data is an IP address (an not some random string or non-sensible IP address).

openssl x509 -enddate -noout -in file.pem
git for-each-ref --sort=-committerdate refs/heads/
openssl rsa -in key.priv -pubout > key.pub
2015-04-28 19:10:17
User: krizzo

This will extract the public key that is stored in the private key using openssl.

egrep 'word1.*word2' --color /path/file.log |more
2015-04-28 15:09:45
User: alissonf
Functions: egrep

grep for 2 words existing on the same line

for a in $(ls /usr/sbin /usr/bin); do ps -fC $a;done|grep -v PPID
2015-04-27 18:15:56
User: knoppix5
Functions: grep ls ps

Thanks to pooderbill for the idea :-)

find . -type f -name '*' -exec md5sum '{}' + > hashes.txt
input=a.pdf ; pages=`pdftk $input dump_data | grep -i numberofpages | cut -d" " -f 2`; pdftk A=$input shuffle A1-$[$pages/2] A$pages-$[$pages/2+1] output "${input%.*}.rearranged.${input##*.}"
2015-04-26 20:05:20
User: kobayashison
Functions: cut grep

Rearrange pdf document coming from a simplex document feed scanner, feeded first with odd pages, then with even pages from the end. Needs pdftk >1.44 w/ shuffle.

Similar to http://www.commandlinefu.com/commands/view/7965/pdf-simplex-to-duplex-merge where there are 2 separate documents, odd and even

perl -e 'for(;;sleep 1){printf"\r"."%.4b "x6,split"",`date +%H%M%S`}'
timeDNS() { parallel -j0 --tag dig @{} "$*" ::: | grep Query | sort -nk5; }
du -sk -- * | sort -n | perl -pe '@SI=qw(K M G T P); s:^(\d+?)((\d\d\d)*)\s:$1." ".$SI[((length $2)/3)]."\t":e'
2015-04-26 08:07:27
Functions: du perl sort

Tested on MacOS and GNU/Linux.

It works in dirs containing files starting with '-'.

It runs 'du' only once.

It sorts according to size.

It treats 1K=1000 (and not 1024)

sudo npm cache clean -f | sudo npm install -g n | sudo n stable
sudo mtr -s 1472 -B 0 -oLDRSWNBAWVJMXI <ip address>
2015-04-24 13:46:36
User: bort
Functions: sudo

Uses packet size 1472, padded with zeroes, and shows more columns with jitter statistics to the right. This is a greatly improved version of traceroute.

du -sc .[!.]* * |grep '^[0-9]{4}'
2015-04-24 10:51:13
User: gander
Functions: du grep

thanks to GREP_COLOR the output will highlite the first 4 digits. if all files are few MB only, this gives a quick overview of how many powers of 10 bigger than 1MB they really are, a logarithmic scale. same works if files are more than 1GB when you replace the "4" by a "7", I usually use "5" in order to manually decide what files to delete...

test "$(md5sum /local/file | cut -d' ' -f1)" == "$(ssh root@xen -- md5sum /remote/file | cut -d' ' -f1)" && echo "Match" || echo "Differ"
2015-04-24 03:09:33
User: gnif
Functions: echo test

This method does not transfer the contents of the entire file, instead it computes a md5 sum of the file on each end so that large files can be compared without transferring them across the net.

du -h -d 1 | ack '\d+\.?\d+G' | sort -hr
git rev-list --reverse --topo-order master... | while read rev; do git checkout preview; git cherry-pick $rev || break; done
2015-04-23 14:28:06
User: shadyvb
Functions: read
Tags: git preview

Creating feature-branches off master, and trying to merge them in an integration branch (preview), sometimes causes conflicts because the feature-branch might hold changes from 'master' that aren't on preview yet. So this ensures only the commits added to the feature-branch are moved to integration (preview).

Note: This assumes you're currently on the feature-branch. Adjust 'master/preview' branch names to suit your environment.

tail +### MYFILE
2015-04-23 11:49:15
User: pooderbill
Functions: tail

Useful for finding newly added lines to a file, tail + can be used to show only the lines starting at some offset. A syslog scanner would look at the file for the first time, then record the end_of_file record number using wc -l. Later (hours, days), scan only at the lines that were added since the last scan.

Blocking ip: arp -s ip_of_host 0, Unblocking ip: arp -d ip_blocked
2015-04-22 19:00:13
User: andregyn62
Functions: arp

When you block any hosts using this method, the hosts can't do anything in the network.

The block is applied on firewall or gateway of the network.

:bufdo :%s/<what-was>/replace-to/g | w!
2015-04-22 15:05:47

you open multiple files and you have a pattern to be replace on each one of them.

For example the pattern is like this spread across hundred's of files.



The goal is to remove the hyphen ('-') and replace with space on file{1..3}

It should look like

package1 1.12

package2 2.33

Here how it can be done.

vim file{1..3}

:bufdo :%s/-\([0-9]\)/ \1/g | w!

"a1" 2L, 30C written

"a2" 2L, 30C written

"a3" 2L, 27C written

ffmpeg -ss 00:00:00.000 -t 10 -i filename.avi -vf scale=320:-1 -r 10 /tmp/output.gif
2015-04-22 06:52:03
User: maxwux

-ss start time

-t duration

-i file name

-vf scale=320:-1 scale 320 X auto

-r fps

view + LOGFILE
2015-04-21 11:23:01
User: pooderbill

view is the command: vi -r which opens a file in read-only mode. The + character jumps to the bottom of the logfile where the most relevant information starts. Other aliases can be created for commonly viewed logfiles.

git diff --word-diff --color-words | aha > index.html && firefox index.html
2015-04-20 13:09:44
User: pooderbill
Functions: ps
Tags: grep function ps

ps and grep is a dangerous combination -- grep tries to match everything on each line (thus the all too common: grep -v grep hack). ps -C doesn't use grep, it uses the process table for an exact match. Thus, you'll get an accurate list with: ps -fC sh rather finding every process with sh somewhere on the line.

openssl req -nodes -newkey rsa:2048 -keyout server.key -out server.csr -subj "/C=BR/ST=State/L=City/O=Company Inc./OU=IT/CN=domain.com"