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.


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.

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

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

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
-3

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
10

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
2

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
1

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
-4

Use the following key binding to search

----------------------------------------------------------------

ng

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

nG

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

/pattern

: 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.

n

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

N

: Go to previous match.

mletter

: Mark the current position with letter.

'letter

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

'^ or g

: Go to start of file.

'$ or G

: Go to end of file.

s

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

= or Ctrl+g

: File information.

F

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

-option

: Toggle command-line option -option.

h

: 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
1

Display some text on the wallpaper especially warning messages

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

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
3

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
2

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
1

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

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
4

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.