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 | grep -C3 "^[[:blank:]]\{1,5\}NUMBER[[:blank:]]"
2009-05-17 18:19:55
User: lv4tech
Functions: cat grep

This is useful for displaying a portion of a FILE that contains an error at line NUMBER

while true; do cat /usr/src/linux/kernel/signal.c > /dev/dsp; done
2009-05-16 14:44:57
Functions: cat

replace "/usr/src/linux/kernel/signal.c" with any file you want and listen to its output ! :P

you can also replace "cat" with "echo" or anything you can come up with

have fun :-}

cat /etc/*issue
cat /etc/psa/.psa.shadow
2009-04-30 18:08:12
User: jigglebilly
Functions: cat

I'm sure almost everybody knows this by now. This command will pull the password for the admin login of any plesk machine.

p=$(netstat -nate 2>/dev/null | awk '/LISTEN/ {gsub (/.*:/, "", $4); if ($4 == "4444") {print $8}}'); for i in $(ls /proc/|grep "^[1-9]"); do [[ $(ls -l /proc/$i/fd/|grep socket|sed -e 's|.*\[\(.*\)\]|\1|'|grep $p) ]] && cat /proc/$i/cmdline && echo; done
2009-04-30 12:39:48
User: j0rn
Functions: awk cat grep ls netstat sed

Ok so it's rellay useless line and I sorry for that, furthermore that's nothing optimized at all...

At the beginning I didn't managed by using netstat -p to print out which process was handling that open port 4444, I realize at the end I was not root and security restrictions applied ;p

It's nevertheless a (good ?) way to see how ps(tree) works, as it acts exactly the same way by reading in /proc

So for a specific port, this line returns the calling command line of every thread that handle the associated socket

yes '' | cat -n
sudo cat /dev/mem > /dev/dsp
( cat badfile.log ; tac badfile.log | tac ) > goodfile.log
2009-04-21 22:06:05
User: flux
Functions: cat tac

man tac

When there is a bad block in the middle of your file, you can see its begninning with `cat' and its end with `tac'. But both commands terminates with an error. So this sequence rebuilds a new file without badblock.

2009-04-17 13:16:56
User: minliu2k
Functions: cat

^V means CTRL-V

[ENTER] means ENTER key

cat <filename> | perl -e '$/ = ""; $_ = <>; s/<!--.*?-->//gs; print;'
2009-04-15 20:29:11
User: unixx
Functions: cat perl

xml with verbose commenting can be difficult to read. remove comments from xml.

sudo cat /dev/vcs1 | fold -w 80
2009-04-15 08:49:48
User: animoid
Functions: cat fold sudo

This will view the console and assumes the screen is 80 characters wide.

Use /dev/vcs2 for the next virtual console.. etc.

command > tmp && cat logfile.txt >> tmp && tmp > logfile.txt && rm tmp
2009-04-05 22:00:32
User: akoumjian
Functions: cat command rm

Adds the stdout (standard output) to the beginning of logfile.txt. Change "command" to whatever command you like, such as 'ls' or 'date', etc. It does this by adding the output to a temporary file, then adding the previous contents of logfile.txt to the temp file, then copying the new contents back to the logfile.txt and removing the temp file.

diff <(ssh alice cat /etc/apt/sources.list) <(ssh bob cat /etc/apt/sources.list)
cat /var/log/secure | grep smtp | awk '{print $9}' | cut -f2 -d= | sort | uniq -c | sort -n | tail
2009-03-30 15:49:54
User: empulse
Functions: awk cat cut grep sort uniq

Searches /var/log/secure for smtp connections then lists these by number of connections made and hosts.

cat /var/log/secure | grep sshd | grep Failed | sed 's/invalid//' | sed 's/user//' | awk '{print $11}' | sort | uniq -c | sort -n
2009-03-30 15:48:24
User: empulse
Functions: awk cat grep sed sort sshd uniq

Searches the /var/log/secure log file for Failed and/or invalid user log in attempts.

cat *.mpg > all.mpg
2009-03-27 04:49:18
User: smcpherson
Functions: cat

Good old cat & output redirection. Using this method you can combine all kinds of things - even mpeg files. My video camera makes a series of .mpeg files that are broken into 4gb chunks. Using this command I can easily join them together. Even better, combined with the cp command the files can be copied and joined in one step.

watch -n1 --differences cat /proc/meminfo
cat /dev/cdrom > ~/mydisk.iso
2009-03-26 05:54:41
User: sata
Functions: cat
Tags: Linux

Generate the iso from the disk, easily.

same as "dd if=/dev/cdrom of=~/mydisk.iso"

xclip -o > /tmp/spell.tmp; aspell check /tmp/spell.tmp ; cat /tmp/spell.tmp | xclip
2009-03-26 00:49:59
User: alperyilmaz
Functions: cat

xclip -o > /tmp/spell.tmp # Copy clipboard contents to a temp file

aspell check /tmp/spell.tmp # Run aspell on that file

cat /tmp/spell.tmp | xclip # Copy the results back to the clipboard, so that you can paste the corrected text

I'm not sure xclip is installed in most distributions. If not, you can install x11-apps package

cat -v -t -e
2009-03-24 19:29:03
User: alperyilmaz
Functions: cat
Tags: cat

Useful to detect number of tabs in an empty line, DOS newline (carriage return + newline).

A tool that can help you understand why your parsing is not working.

vimdiff foo.c <(bzr cat -r revno:-2 foo.c)
cat schema.sql data.sql test_data.sql | mysql -u user --password=pass dbname
2009-03-24 08:39:40
User: tristan_ph
Functions: cat
Tags: mysql cat

Be aware of using the --password argument as it will appear your password in plain text on the screen. You may use -p argument instead, it will prompt you to enter you password in hidden mode.

cat file.txt | sort | uniq -dc
2009-03-21 18:15:14
User: Vadi
Functions: cat sort uniq

Displays the duplicated lines in a file and their occuring frequency.

for file in `find . -type f`; do cat $file; done | wc -l
for i in `find /sys/devices/*/*/usb* -name level` ; do echo -n "$i: " ; cat $i ; done