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 using cat from sorted by
Terminal - Commands using cat - 428 results
cat urls.txt | wget -i- -T 10 -t 3 --waitretry 1
cat urls.txt | xargs -n1 curl -O --max-time 10 --retry 3 --retry-delay 1
cat /var/log/nginx/access.log | grep -oe '^[0-9.]\+' | perl -ne 'system("geoiplookup $_")' | grep -v found | grep -oe ', [A-Za-z ]\+$' | sort | uniq -c | sort -n
2012-05-08 13:28:25
User: theist
Functions: cat grep perl sort uniq
Tags: sort uniq geoip
-1

Per country GET report, based on access log. Easy to transform to unique IP

while true; do sudo cat /dev/input/mouse0|read -n1;streamer -q -o /tmp/cam.jpeg -s 640x480 > /dev/null 2>&1; sleep 10;done
2012-04-22 01:51:30
User: SQUIIDUX
Functions: cat read sleep sudo
Tags: cat streamer
4

This takes a webcam picture every everytime the mouse is moved (waits 10 seconds between checking for movement) and stores the picture wherever you want it.

Ideas:

Use in conjunction with a dropbox type application to see who is using your computer

Use /dev/input/mice if /dev/input/mouse* doesn't work

Use the bones of this to make a simple screensaver

while true; do iptables -nvL > /tmp/now; diff -U0 /tmp/prev /tmp/now > /tmp/diff; clear; cat /tmp/diff; mv /tmp/now /tmp/prev; slee p 1; done
2012-04-15 00:02:33
Functions: cat diff iptables mv
0

this alternative shows the differences as they occur so that they are made plain

yes "" | cat -n | awk '{print "S=`echo All work and no play makes Jack a dull boy. | cut -c",($1 - 1) % 43 + 1 "`;echo -n \"$S\";seq 500000 > /dev/null"}'| bash
sed G input.txt | cat -s
cat z.log | perl -ne 'BEGIN{ print "DATE;RATE\n"; } /\[(\d.*)\]/ && print $1; /CURRENT RATE: +(\S+) msg.*/ && print ";" .$1 . "\n"; '
2012-04-03 13:52:20
User: hute37
Functions: cat perl
1

extract data in multiline blocks of data with perl pattern matching loop

pdftk A=1.pdf B=2.pdf C=3.pdf cat C A output CA.pdf
pdftk 1.pdf 2.pdf cat output 12.pdf
cat > file_name
2012-03-27 11:38:09
Functions: cat
-2

Write script or commands in notepad/Editplus/MS word etc, copy the contents, type the above command and click on enter now, paste by right click-ing the mouse. Entire contents in the clip-board gets pasted now again click on Enter to go to new line/next line. Press Ctrl+D to close/save the file. Not always required to vi to create a new file.

wget -q ip.nu && cat index.html
find . -type f -name "*.*" -exec cat {} > totalLines 2> /dev/null \; && wc -l totalLines && rm totalLines
ps h --ppid $(cat /var/run/apache2.pid) | awk '{print"-p " $1}' | xargs sudo strace
2012-03-21 01:59:41
Functions: awk cat ps sudo xargs
2

Like the original version except it does not include the parent apache process or the grep process and adds "sudo" so it can be run by user.

for a in $(cat sample.txt); do echo "${#a} $a";done|sort -n
for a in $(cat sample.txt); do echo "$(wc -m<<<$a) $a";done|sort -n
2012-03-15 08:51:42
User: knoppix5
Functions: cat echo sort
0

optionally you can add

|cut -d' ' -f2|uniq

to the end of the command line.

x=1024; y=32768; cat <(echo -e "P5\n$x $y\n255\n") <(dd if=/dev/sda1 bs=$x count=$y) > sda1.pgm
2012-03-06 03:09:16
User: adeverteuil
Functions: cat dd echo
Tags: dd images pnm pgm
1

Keep width to a power of 2 to see patterns emerge. 512 is good. So is 4096 for huge maps.

PNM headers are super basic.

http://netpbm.sourceforge.net/doc/pbm.html

cat z.log | cut -d ':' -f1,2 | uniq -c
cat z.log | cut -d ':' -f1 | sort | uniq | xargs -l1 -iFF echo 'echo FF $(cat z.log | grep -e "^FF" | grep -e Timeout | wc -l )' | bash
cat z.log | grep Timeout | cut -d ':' -f1 | sort | uniq -c
cat file.txt | putclip
#(see sample) $ cat x | perl -pe 'BEGIN{ print "TIME;...\n"; } s!(\S+) - (\S+) - \[(\d\d)/(\S\S\S)/(\S+):(\d\d):(\d\d:\d\d) \S+\] "(\S+) (.*/)(\S+)(?:\.([^?]*)(\?\S*)?) HTTP/\S+" (\d+) (\S+)!$3-$4-$5 $6:$7;$6;$2;$1;$8;$13;1;$14;$11;$10;$9;$12;!' > x.csv
2012-02-10 16:58:50
User: hute37
Functions: cat perl
2

- excel date compatible with a separate hour field

- added a fixed 1 for easier request counter aggregation

- split URL in directory, filename, fileext, query

- used with tomcat valve with response bytes replaced by elapsed time

x="/tmp/auth.html";sudo cat /var/log/auth.log | logtool -o HTML >$x;xdg-open $x;rm $x
2012-02-09 13:36:21
Functions: cat rm sudo
0

similar to previous except this exports to a temporary file, opens that file with your default web browser, then deletes it.

PID=`ps | grep process_name | grep -v grep | head -n 1 | awk '{print $1}'`; cat /proc/$PID/smaps | grep heap -A 2
genRandomText() { cat /dev/urandom|tr -dc 'a-zA-Z'|head -c $1 }
2012-01-21 00:51:34
User: thomasba
Functions: cat head tr
Tags: random urandom
0

Using urandom to get random data, deleting non-letters with tr and print the first $1 bytes.