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 tagged text from sorted by
Terminal - Commands tagged text - 26 results
sort in-file.txt | uniq -u > out-file.txt
ls -1 | xargs ruby -e'puts ARGV.shuffle'
gocr -i ~/Screenshot.png
2013-02-28 07:38:13
User: totti

Image to text converter.

Convert your scanned book in image format like .png, .jpg into editable text format.

OCR ==> Optical Code Reader

find -type f | xargs file | grep ".*: .* text" | sed "s;\(.*\): .* text.*;\1;"
sort -g -o list.txt{,}
2011-11-15 19:59:28
User: jambino
Functions: sort
Tags: sorting text

sorts the contents of a file without the need for a second file to take the sorted output.

This was previously entered as `sort -g list.txt -o $_` but as others have pointed out the $_ references the previous command. so this would've worked had that been the second part of a command joined with && like:

cat list.txt && sort -g list.txt -o $_

The user below me Robin had the most correct command.

curl http://www.commandlinefu.com/commands/browse/sort-by-votes/plaintext/[0-9000:25] | grep -vE "_curl_|\.com by David" > clf-ALL.txt
2011-11-08 12:19:48
User: totti
Functions: grep

Faster then other method using wget

For obtain all commands use

nu=`curl http://www.commandlinefu.com/commands/browse |grep -o "Terminal - All commands -.*results$" | grep -oE "[[:digit:],]{4,}" | sed 's/,//'`; curl http://www.commandlinefu.com/commands/browse/sort-by-votes/plaintext/[0-"$nu":25] | grep -vE "_curl_|\.com by David" > clf-ALL.txt

For more version specific

nu=`curl http://www.commandlinefu.com/commands/browse |grep -o "Terminal - All commands -.*results$" | grep -oE "[[:digit:],]{4,}" | sed 's/,//'`; curl http://www.commandlinefu.com/commands/browse/sort-by-votes/plaintext/[0-"$nu":25] | grep -vE "_curl_|\.com by David" > clf-ALL_"$nu".txt

Also download dirctly from my dropbox

My drop box invitaion link is http://db.tt/sRdJWvQq . Use it and get free 2.5 GB space.

upper() { echo ${@^^}; }
lower() { echo ${@,,}; }
vi +4 /etc/mtab
2011-09-15 19:18:00
User: totti
Functions: vi
Tags: edit text line goto

This is not printing, real editing using the text editor.

sed 's/.$//' Win-file.txt
less file.ext
2011-09-13 10:29:27
User: totti
Functions: less
Tags: less text search

Use the following key binding to search



: Jump to line number n. Default is the start of the file.


: Jump to line number n. Default is the end of the file.


: Search for pattern. Regular expressions can be used. [/ = slash] Press / and then Enter to repeat the previous search pattern. Press ESC and then u to undo search highlighting.


: Go to next match (after a successful search).


: Go to previous match.


: Mark the current position with letter.


: Return to position letter. [' = single quote]

'^ or g

: Go to start of file.

'$ or G

: Go to end of file.


: Save current content (got from another program like grep) in a file.

= or Ctrl+g

: File information.


: continually read information from file and follow its end. Useful for logs watching. Use Ctrl+c to exit this mode.


: Toggle command-line option -option.


: Help.

tr -d "\r" < file.vcf | tr "\0" " " > file.vcf.txt
tr -d "\r" < dos.txt > linux.txt
hexdump -c <file>
wallpaperWarn() { BG="/desktop/gnome/background/picture_filename"; convert "`gconftool-2 -g $BG`" -pointsize 70 -draw "gravity center fill red text 0,-360 'Warn' fill white text 0,360 'Warn'" /tmp/w.jpg; gconftool-2 --set $BG -t string "/tmp/w.jpg"; }
2011-09-07 19:00:40
User: totti

Display some text on the wallpaper especially warning messages

sort -R
2011-07-15 15:35:27
User: RyanM
Functions: sort

Randomizes a file. The opposite of sort is sort -R!

perl -ne 'print if !$a{$_}++'
2011-02-17 02:18:44
User: doherty
Functions: perl

Reads stdin, and outputs each line only once - without sorting ahead of time. This does use more memory than your system's sort utility.

find . -name "*.php" -type f -exec sed -i "\$d" '{}' \;
2010-12-09 16:42:22
User: tedkulp
Functions: find sed
Tags: sed find text

Used this command recently to remove the trailing ?> from all the files in a php project, which has having some unnecessary whitespace issues. Obviously, change *.php to whatever you'd like.

7zr a -mx=9 -ms=on -mhc=on -mtc=off db_backup.sql.7z db_dump.sql
2010-10-22 21:05:58
User: mandx

These re the best option combination that works fine for compressing my database dumps. It's possible that there are another option or value that might improve the compression ratio, by these are the ones that worked, the syntax for 7zr it's a little messy...

perl -wl -e [email protected]=<>; for $i (0 .. $#f) { $r=int rand ($i+1); @f[$i, $r][email protected][$r,$i] if ($i!=$r); } chomp @f; print join $/, @f;' try.txt
random -f <file>
cat ~/SortedFile.txt | perl -wnl -e [email protected]=<>; END{ foreach $i (reverse 0 .. $#f) { $r=int rand ($i+1); @f[$i, $r][email protected][$r,$i] unless ($i==$r); } chomp @f; foreach $line (@f){ print $line; }}'
2009-09-24 15:42:43
User: drewk
Functions: cat perl

The sort utility is well used, but sometimes you want a little chaos. This will randomize the lines of a text file.

BTW, on OS X there is no

| sort -R

option! There is also no

| shuf

These are only in the newer GNU core...

This is also faster than the alternate of:

| awk 'BEGIN { srand() } { print rand() "\t" $0 }' | sort -n | cut -f2-
find . | xargs file | grep ".*: .* text" | sed "s;\(.*\): .* text.*;\1;"
dos2unix file.txt
cat <<.>> somefilename
2009-07-10 17:45:42
User: tomlouie
Functions: cat
Tags: text

If you just want to write or append some text to a file without having to run a text editor, run this command. After running the command, start typing away. To exit, type . on a line by itself.

Replacing the >> with a single > will let you overwrite your file.