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 cat from sorted by
Terminal - Commands using cat - 446 results
cat -n file or cat -b file
2009-09-24 12:18:40
User: eastwind
Functions: cat file

cat -n file : number all line

cat -b file : number only non empty line

see man cat

cat filename | uuencode filename | mail -s "Email subject" [email protected]
2009-09-21 04:13:50
User: amaymon
Functions: cat mail uuencode
Tags: cat mail

uuencode the file to appear as an attachment

cat filename | mail -s "Email subject" [email protected]
2009-09-20 01:38:23
Functions: cat mail
Tags: cat mail

This just reads in a local file and sends it via email. Works with text or binary. *Requires* local mail server.

cat *.sql | mysql <db_name>
cat /var/lib/dpkg/info/*.list > /tmp/listin ; ls /proc/*/exe |xargs -l readlink | grep -xvFf /tmp/listin; rm /tmp/listin
2009-09-09 18:09:14
User: kamathln
Functions: cat grep ls readlink rm xargs
Tags: Debian find dpkg

This helped me find a botnet that had made into my system. Of course, this is not a foolproof or guarantied way to find all of them or even most of them. But it helped me find it.

cat testfile | hexdump -C
echo capitalize | { dd bs=1 count=1 conv=ucase 2> /dev/null; cat ;}
cat /etc/passwd | openssl aes-256-cbc -a -e -pass pass:password | netcat -l -p 8080
2009-09-04 20:04:24
User: flip387
Functions: cat

Using OpenSSL we can encrypt any input we wish and then use Netcat to create a socket which can be connected to from an externally source (even using a Web Browser)

vimdiff <(svn cat "$1") "$1"
2009-09-04 18:41:40
User: plasticboy
Functions: cat
Tags: svn vim diff color

This will diff your local version of the file with the latest version in svn. I put this in a shell function like so:

svd() { vimdiff <(svn cat "$1") "$1"; }
cat /service/solr/log/main/current | tai64nlocal | grep "\(`date '+%F %H'`\|`date '+%F %H %M' | awk '{print $1" 0"$2-1":"$3}'`\)" | grep QTime | awk '{print $NF}' | awk -F\= '{ s += $2} END {print s/NR}'
cat nicescript |ssh middlehost "cat | ssh -a [email protected] 'cat > nicescript'"
2009-08-25 08:11:12
User: syladmin
Functions: cat ssh
Tags: ssh scp

middlehost allows ssh access from where you are but not securehost.

Use nice ssh piping to simulate scp through A => B => C

setting up the shell function if left as an exercise for the reader. ;-)

Agent forwarding should avoid password typing.

echo `date +%m/%d/%y%X |awk '{print $1;}' `" => "` cat /proc/acpi/thermal_zone/THRM/temperature | awk '{print $2, $3;}'` >> datetmp.log
2009-08-24 21:26:29
User: ninadsp
Functions: awk cat echo

Uses the data in the /proc system, provided by the acpid, to find out the CPU temperature. Can be run on systems without lm-sensors installed as well.

cat filename | tr '\n' '\0' | du -hsc ?files0-from=-
2009-08-21 18:36:49
User: Diluted
Functions: cat du tr

du only accepts lines ending with a NUL, which can be a pain to create. This solves that issue.

cat /proc/cpuinfo
cat filename | grep .
2009-08-09 01:00:59
User: fraktil
Functions: cat grep
Tags: cat Linux grep

Pipe any output to "grep ." and blank lines will not be printed.

cat files.txt | xargs tar -cv | tar -x -c $DIR/
2009-08-06 22:55:21
User: lingo
Functions: cat tar xargs

If you want certain files out of a directory hierarchy, this will copy just the listed files, but will create the directory hierarchy in the new location ($DIR/)

sudo cat /usr/share/icons/*/*/* > /dev/dsp
2009-08-06 03:12:27
User: 12345678
Functions: cat sudo

Plays the sound of the file, should sound like *some* kind of music, most files sound like static but some are really cool.


sudo cat /dev/sda > /dev/dsp sudo cat /dev/sda5 | aplay

Check out http://bbs.archlinux.org/viewtopic.php?id=70937 for more variations!

semi-dupe--like http://www.commandlinefu.com/commands/view/985/generate-white-noise but with different syntax and program.

cat /etc/debian_version
2009-08-05 14:47:05
User: caiosba
Functions: cat

Easy way to find out what Debian version your machine is running

cat file-that-failed-to-download.zip | curl -C - http://www.somewhere.com/file-I-want-to-download.zip >successfully-downloaded.zip
2009-08-05 13:33:06
Functions: cat

If you are downloading a big file (or even a small one) and the connection breaks or times out, use this command in order to RESUME the download where it failed, instead of having to start downloading from the beginning. This is a real win for downloading debian ISO images over a buggy DSL modem.

Take the partially downloaded file and cat it into the STDIN of curl, as shown. Then use the "-C -" option followed by the URL of the file you were originally downloading.

cat frame/*.mpeg | ffmpeg -i $ID.mp3 -i - -f dvd -y track/$ID.mpg 2>/dev/null
2009-08-04 06:31:50
User: pamirian
Functions: cat

This is an extract from a larger script which formats the video for DVD. The videos I use have no audio track so I need to add one. Tweak as you like...

find . -type f -name "*.c" -exec cat {} \; | wc -l
2009-07-30 10:06:51
User: foremire
Functions: cat find wc

use find to grep all .c files from the target directory, cat them into one stream, then piped to wc to count the lines

cat file | tee >> file
2009-07-30 07:34:03
User: GeckoDH
Functions: cat file tee

The command `cat file >> file` failes with the following error message:

cat: file: input file is output file

`tee` is a nice workaround without using any temporary files.

cat /proc/net/ip_conntrack | grep ESTABLISHED | grep -c -v ^#
for file in *.001; do NAME=`echo $file | cut -d. -f1,2`; cat "$NAME."[0-9][0-9][0-9] > "$NAME"; done
2009-07-29 10:04:26
User: jaymzcd
Functions: cat cut file

If you use newsgroups then you'll have come across split files before. Joining together a whole batch of them can be a pain so this will do the whole folder in one.

buffer () { tty -s && return; tmp=$(mktemp); cat > "${tmp}"; if [ -n "$1" ] && ( ( [ -f "$1" ] && [ -w "$1" ] ) || ( ! [ -a "$1" ] && [ -w "$(dirname "$1")" ] ) ); then mv -f "${tmp}" "$1"; else echo "Can't write in \"$1\""; rm -f "${tmp}"; fi }
2009-07-27 20:21:15
User: Josay
Functions: cat echo mv rm tty
Tags: redirection

A common mistake in Bash is to write command-line where there's command a reading a file and whose result is redirected to that file.

It can be easily avoided because of :

1) warnings "-bash: file.txt: cannot overwrite existing file"

2) options (often "-i") that let the command directly modify the file

but I like to have that small function that does the trick by waiting for the first command to end before trying to write into the file.

Lots of things could probably done in a better way, if you know one...