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 - 345 results
find . -iname "*.cpp" -exec perl -ni -e 'chomp; print "$_\n"' {} \;
2009-02-18 14:12:24
User: grundprinzip
Functions: find perl

Adds a newline to the end of all cpp files in the directory to avoid warnings from gcc compiler.

perl -pe 's/\d+/++$n/e' file.txt
perl -pi -e 's:^V^M::g' <filenames>
2009-02-16 21:17:40
User: starchox
Functions: perl

That "^M" is Ctrl-M, which is a carriage return, and is not needed in Unix file systems.

Where ^V is actually Ctrl-V and ^M is actually Ctrl-M (you must type these yourself, don't just copy and paste this command). ^V will not be displayed on your screen.

find . -type f -exec grep -l XXX {} \;|tee /tmp/fileschanged|xargs perl -pi.bak -e 's/XXX/YYY/g'
2009-02-16 02:55:23
User: drossman
Functions: find grep perl tee xargs

Find all files that contain string XXX in them, change the string from XXX to YYY, make a backup copy of the file and save a list of files changed in /tmp/fileschanged.

cat file.php | perl -p -e 's/(\$|->)(str|arr|obj|int|flt|boo|bool|mix|res)([A-Z])/$1\L$3/g'
2009-02-10 14:37:12
User: root
Functions: cat perl

This removes the type prefix used in Hungarian notation (v. bad) for PHP variables. Eg. variables of the form $intDays, $fltPrice, $arrItems, $objLogger convert to $days, $price, $Items, $logger.

perl -e "''=~('(?{'.('-^@.]|(;,@/{}/),[\\\$['^'],)@)[\`^@,@[*@[@?}.|').'})')"
find . -name "*.jpg" | perl -ne'chomp; $name = $_; $quote = chr(39); s/[$quote\\!]/_/ ; print "mv \"$name\" \"$_\"\n"'
perl -e "use SOAP::Lite"
2009-02-06 15:26:37
User: leprasmurf
Functions: perl

Quick command to check if Perl library is installed on your server.

perl -pe 's/.+;//' ~/.zsh_history | sort | uniq -c | sort -r|head -10
perl -le 'print join ", ", map { chomp; $_ } <>'
2009-02-06 12:50:43
User: jozef
Functions: join perl

joins multiple lines to create single line with comma separated values. for example if we have an email addresses one per line (copy&paste from spreadsheet) it will oputput one line with comman separated addresses to put it to email client.

perl -MHTML::Entities -ne 'print encode_entities($_)' /tmp/subor.txt
2009-02-06 12:44:24
User: jozef
Functions: perl

Encodes HTML entities from input (file or stdin) so it's possible to directly past the result to a blog or HTML source file.

grep -r -l xxxxx . | xargs perl -i -pe "s/xxxxx/yyyyy/g"
2009-02-06 08:18:50
User: hassylin
Functions: grep perl xargs

This script first find all files which contains word xxxxx recursively. Then replace the word xxxxx to yyyyy of the files.

Use case:

- Web site domain change

- Function name change of the program

find . -name "*.txt" | xargs perl -pi -e 's/old/new/g'
2009-02-06 00:28:03
User: neztach
Functions: find perl xargs

syntax follows regular command line expression.

example: let's say you have a directory (with subdirs) that has say 4000 .php files.

All of these files were made via script, but uh-oh, there was a typo!

if the typo is "let's go jome!" but you meant it to say "let's go home!"

find . -name "*.php" | xargs perl -pi -e "s/let\'s\ go\ jome\!/let\'s\ go\ home\!/g"

all better :)

multiline: find . -name "*.php" | xargs perl -p0777i -e 's/knownline1\nknownline2/replaced/m'

indescriminate line replace: find ./ -name '*.php' | xargs perl -pi -e 's/\".*$\"/\new\ line\ content/g'

perl -pi -e 's/THIS/THAT/g' fileglob*
2009-02-05 19:19:52
User: elofland
Functions: perl

changes THIS to THAT in all files matching fileglob* without using secondary files

perl -e '$b="bork"; while(<STDIN>){$l=`$_ 2>&1`; $l=~s/[A-Za-z]+/$b/g; print "$l$b\@$b:\$ ";}'
2009-02-05 18:33:40
User: fonik
Functions: perl

Bork, bork, bork!

To keep it short, the first terminal line doesn't show a prompt.

perl -pi -e 's/localhost/replacementhost/g' *.php
perl -i -pe "s/old/new/g" *
2009-02-05 12:07:27
User: pandres
Functions: perl

Replaces every ocurrence of 'old' for 'new' in all files specified. After the 'i' char you can put a '~' or whatever to create a backup file for each replaced with the name equal to the original plus character.

function sshdel { perl -i -n -e "print unless (\$. == $1)" ~/.ssh/known_hosts; }
2009-02-03 16:20:50
User: xsawyerx
Functions: perl

sometimes you got conflicts using SSH (host changing ip, ip now belongs to a different machine) and you need to edit the file and remove the offending line from known_hosts. this does it much easier.

perl -pi.bk -e's/foo/bar/g' file1 file2 fileN
2009-01-29 09:51:11
User: xsawyerx
Functions: perl

the addition of ".bk" to the regular "pie" idiom makes perl create a backup of every file with the extension ".bk", in case it b0rks something and you want it back

perl -pi -e's/foo/bar/g' file1 file2 fileN
2009-01-29 09:47:01
User: xsawyerx
Functions: perl

The "g" at the end is for global, meaning replace all occurrences and not just the first one.