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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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



Commands using perl from sorted by
Terminal - Commands using perl - 346 results
wget -q -O- http://www.gutenberg.org/dirs/etext96/cprfd10.txt | sed '1,419d' | tr "\n" " " | tr " " "\n" | perl -lpe 's/\W//g;$_=lc($_)' | grep "^[a-z]" | awk 'length > 1' | sort | uniq -c | awk '{print $2"\t"$1}'
2009-05-04 16:00:39
User: alperyilmaz
Functions: awk grep perl sed sort tr uniq wget

This command might not be useful for most of us, I just wanted to share it to show power of command line.

Download simple text version of novel David Copperfield from Poject Gutenberg and then generate a single column of words after which occurences of each word is counted by sort | uniq -c combination.

This command removes numbers and single characters from count. I'm sure you can write a shorter version.

for i in `screen -ls | perl -ne'if(/^\s+\d+\.([^\s]+)/){print $1, " "}'`; do gnome-terminal -e "screen -x $i"; done
2009-04-25 22:39:24
User: hank
Functions: perl
Tags: screen Linux perl

There was another line that was dependent on having un-named screen sessions. This just wouldn't do. This one works no matter what the name is. A possible improvement would be removing the perl dependence, but that doesn't effect me.

ldapsearch -v -H ldap://<server> -x -D cn=<johndoe>,cn=<users>,dc=<ourdomain>,dc=<tld> -w<secret> -b ou=<lazystaff>,dc=<ourdomain>,dc=<tld> -s sub sAMAccountName=* '*' | perl -pne 's/(\d{11})\d{7}/"DATE-AD(".scalar(localtime($1-11644473600)).")"/e'
2009-04-22 00:57:34
User: flux
Functions: perl

When Ldapsearch queries an Active directory server, all the dates are shown using a timestamp of 18 digits. This perl regexp decodes them in a more human friendly notation. 11644473600 corresponds to some microsoft epoch.

cat <filename> | perl -e '$/ = ""; $_ = <>; s/<!--.*?-->//gs; print;'
2009-04-15 20:29:11
User: unixx
Functions: cat perl

xml with verbose commenting can be difficult to read. remove comments from xml.

$ perl -pi -e 's/\r\n/\n/g' <finelame>
2009-04-10 22:22:31
Functions: perl
Tags: perl dos2unix

Converts windows lined-style file to unix.

see http://en.wikipedia.org/wiki/Newline

Can be used to convert from linux2dos : just invert \r\n and \n.

u=`curl -d 'dl.start=Free' $(curl $1|perl -wpi -e 's/^.*"(http:\/\/rs.*)" method.*$/$1/'|egrep '^http'|head -n1)|grep "Level(3) \#2"|perl -wpi -e 's/^.*(http:\/\/rs[^\\\\]*).*$/$1/'`;sleep 60;wget $u
perl -ne 'while (/([0-9]+\.){3}[0-9]+/g) {print "$&\n"};' file.txt
watch -tn1 'bc<<<"`date -d'\''friday 21:00'\'' +%s`-`date +%s`"|perl -ne'\''@p=gmtime($_);printf("%dd %02d:%02d:%02d\n",@p[7,2,1,0]);'\'
2009-03-29 19:53:36
User: penpen
Functions: perl watch
Tags: Linux unix date

An improved version of http://www.commandlinefu.com/commands/view/1772/simple-countdown-from-a-given-date that uses Perl to pretty-print the output. Note that the GNU-style '--no-title' option has been replaced by its one-letter counterpart '-t'.

perl -pi -e 's/foo/bar/g' $(grep -rl foo ./*)
2009-03-27 17:21:35
User: dopeman
Functions: grep perl
Tags: perl

This command will replace all instances of 'foo' with 'bar' in all files in the current working directory and any sub-directories.

perl -pi -e 's/foo/bar/g' $(grep -l foo ./*)
2009-03-27 17:18:08
User: dopeman
Functions: grep perl

This command will replace all instances of 'foo' with 'bar' in all files in the current working directory.

function crtonl { perl -i -ape 's/\r\n?/\n/g;' $* ; }
2009-03-25 20:28:32
User: totoro
Functions: perl
Tags: files

Many Mac OS X programs, especially those in Microsoft:Office, create ASCII files with lines terminated by CRs (carriage returns). Most Unix programs expect lines separated by NLs (newlines). This little command makes it trivial to convert them.

perl -e 'print scalar localtime $ARGV[0],"\n" ' epoch
du -hS / | perl -ne '(m/\d{3,}M\s+\S/ || m/G\s+\S/) && print'
2009-03-25 18:06:53
User: Alioth
Functions: du perl

Finds all directories containing more than 99MB of files, and prints them in human readable format. The directories sizes do not include their subdirectories, so it is very useful for finding any single directory with a lot of large files.

perl -e 'print "Hello World!", "\n";'
history | perl -lane '$lsize{$_} = scalar(@F); if($longest<$lsize{$_}) { $longest = $lsize{$_}; print "$_"; };' | tail -n1
perl -e 'print map { $_ . "\n" } @INC;'
perl -0777 -ne 'print "$1\n" while /word-a(.*?)word-b/gs' filename.txt
2009-03-08 11:47:18
User: eleffie
Functions: perl

This command will display all lines between 2 patterns: word-a and word-b

useful for grepping command outputs from file

find $HOME -type f -print | perl -wnlaF'/' -e 'BEGIN{ print "#EXTM3U"; } /.+\.wmv$|.+\.mpg$|.+\.vob$/i and print "#EXTINF:$F[-1]\nfile://$&";' > movies.m3u
perl -pi -e's/<what to find>/<what to replace it with>/g' `grep -Rl <what to find> /<dir>/*`
2009-02-26 19:14:39
User: adampbell
Functions: perl

Finds the string in every file in an entire directory and all its subdirectories and replaces it with a new string. Especially useful when changing a machine's IP address or hostname - run it on /etc.

find . -type d | perl -nle 'print s,/,/,g," $_"' | sort -n | tail
du -b --max-depth 1 | sort -nr | perl -pe 's{([0-9]+)}{sprintf "%.1f%s", $1>=2**30? ($1/2**30, "G"): $1>=2**20? ($1/2**20, "M"): $1>=2**10? ($1/2**10, "K"): ($1, "")}e'
nmap -sS -O -oX /tmp/nmap.xml -v -v && perl nmap2nagios.pl -v -r /tmp/10net.xml -o /etc/nagios/10net.cfg
perl -e 'print 1, 2, 3' > /dev/full
2009-02-19 17:08:13
User: mkc
Functions: perl

The Linux /dev/full file simulates a "disk full" condition, and can be used to verify how a program handles this situation.

In particular, several programming language implementations do not print error diagnostics (nor exit with error status) when I/O errors like this occur, unless the programmer has taken additional steps. That is, simple code in these languages does not fail safely. In addition to Perl, C, C++, Tcl, and Lua (for some functions) also appear not to fail safely.

perl -e 'use MIME::Base64; print encode_base64("encode me plz");'
2009-02-18 22:49:18
User: therek
Functions: perl

MIME::Base64 is a part of Perl5 distribution. You can also use decode_base64 for oposite result.

perl -lpe'1 while s/^([-+]?\d+)(\d{3})/$1.$2/'