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.

Universal configuration monitoring and system of record for IT.

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 cat from sorted by
Terminal - Commands using cat - 435 results
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

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.


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

- 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

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

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

cat /etc/squid/squid.conf | grep -v '^#' | sed '/^$/d'
echo $(cat file)
2011-12-22 23:05:52
User: dtlp747
Functions: cat echo

Example: you have a package.txt you want to install on a system. Instead of this:

cat package.txt




You want it to cat out on one line so you can print "yum install package1 package2 package3"

cat /proc/PID/limits
2011-12-14 16:49:06
User: dmmst19
Functions: cat

When dealing with system resource limits like max number of processes and open files per user, it can be hard to tell exactly what's happening. The /etc/security/limits.conf file defines the ceiling for the values, but not what they currently are, while

ulimit -a

will show you the current values for your shell, and you can set them for new logins in /etc/profile and/or ~/.bashrc with a command like:

ulimit -S -n 100000 >/dev/null 2>&1

But with the variability in when those files get read (login vs any shell startup, interactive vs non-interactive) it can be difficult to know for sure what values apply to processes that are currently running, like database or app servers. Just find the PID via "ps aux | grep programname", then look at that PID's "limits" file in /proc. Then you'll know for sure what actually applies to that process.

cat /etc/debian_version
2011-12-11 11:13:16
User: eastwind
Functions: cat

work on any debian based GNU/Linux distro

cat *
2011-12-08 05:32:14
User: bahamas10
Functions: cat

no need for a for loop when cat takes multiple arguments

find /usr/include/ -name '*.[c|h]pp' -o -name '*.[ch]' -exec cat {} \;|wc -l
2011-12-01 19:58:52
User: kerim
Functions: cat find wc

Count your source and header file's line numbers

For example for java change the command like this

find . -name '*.java' -exec cat {} \;|wc -l

for file in ./*; do cat "$file"; sleep 0.3
2011-11-28 20:10:57
User: DopeGhoti
Functions: cat file sleep

Original submitted version would break if any filenames had whitespaces in them. The command is a Bad Idea anyhow, because you will end up `cat`ing a binary or something else specacularly bad.

for f in *; do clear; cat $f; sleep .3; done
2011-11-25 17:10:47
User: toddkaufmann
Functions: cat sleep

The better alternative to #9756.

I don't think I'd ever use the original command, but this one was so bad I had to post this. Sorry.

1. $(ls) is dumb, and will give errors if you have an alias like "ls -Fs"

2. clear is better and more portable than reset state.

3. if you're interested in differences, then use diff, not cat.

while true; do cat /proc/net/dev; sleep 1; done | awk -v dc="date \"+%T\"" '/eth0/{i = $2 - oi; o = $10 - oo; oi = $2; oo = $10; dc|getline d; close(dc); if (a++) printf "%s %8.2f KiB/s in %8.2f KiB/s out\n", d, i/1024, o/1024}'
2011-11-21 05:24:44
Functions: awk cat printf sleep
Tags: awk sh

poorman's ifstat using just sh and awk. You must change "eth0" with your interface's name.

cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 32
cat <file> > /dev/null
2011-11-12 15:45:27
User: totti
Functions: cat
Tags: ram file cache

Best result when file size less than half of RAM size

date -d @$(echo $(($(date +%s)-$(cat /proc/uptime|cut -d. -f1))))
nocomments () { cat $1 | egrep -v '^[[:space:]]*#|^[[:space:]]*$|^[[:space:]]*;' | sed '/<!--.*-->/d' | sed '/<!--/,/-->/d'; }
2011-11-04 12:47:39
User: RuizTapiador
Functions: cat egrep sed
Tags: sed grep comment

Hide comments and empty lines, included XML comments,

cat /file/way/somelogforexample | grep -o "[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}" | sort -n | uniq -c | sort -n
cat /var/log/auth.log | grep -i "pam_unix(sshd:auth): authentication failure;" | cut -d' ' -f14,15 | cut -d= -f2 | sort | uniq
2011-10-25 04:58:09
User: JohnQUnknown
Functions: cat cut grep sort

This command shows a sorted list of the IP addresses from which there have been authentication errors via SSH (possible script kiddies trying to gain access to your server), it eliminates duplicates so it's easier to read, but you can remove the "uniq" command at the end, or even do a "uniq -c" to have a count of how many times each IP address shows in the log (the path to the log may vary from system to system)

cat myfile.mp3 | ssh user@remotemachine "mplayer -cache 8912 -"
2011-10-22 23:06:44
User: sidis405
Functions: cat ssh

Play local mp3 file on remote machine's speakers through ssh