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.

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



Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

Commands using cat from sorted by
Terminal - Commands using cat - 443 results
pcharc(){ perl -e 'for (0..255) {$_ = chr($_); print if /['$1']/}' | cat -v; echo;}
2010-11-13 00:32:41
User: putnamhill
Functions: cat perl
Tags: perl

Today I needed a way to print various character classes to use as input for a program I was writing. Also a nice way to visualize character classes.

cat index.html | sed 's|"index.html%3Ffeed=rss2"|"http://dynamic-blog.hemca.com/?feed=rss2.html"|g'
2010-11-05 20:27:21
User: strzel_a
Functions: cat sed

Pipe | avoid escaping occurences problems in using sed and make it easier to use

cat file.txt | sed -e /<opening tag>/d -e /<closing tag>/G | sed -e '/./{H;$!d;}' -e 'x;/<string to search>/!d;'
2010-11-04 10:31:15
User: EBAH
Functions: cat sed

Working with log files that contains variable length messages wrapped between open and close tags it may be useful to filter the messages upon a keyword.

This works fine with GNU sed version 4.2 or higher, so pay attention to some unix distros (solaris, hp-ux, etc.).

Linux should be ok.

ps -u $USER -lf | grep -vE "\-bash|sshd|ps|grep|PPID" > .tmpkill; if (( $(cat .tmpkill | wc -l) > 0 )); then echo "# KILL EM ALL"; cat .tmpkill; cat .tmpkill | awk '{print $4}' | xargs kill -9; else echo "# NOTHING TO KILL"; fi; cat .tmpkill; rm .tmpkill;
2010-11-04 04:16:50
User: zsugiart
Functions: awk cat echo grep kill ps rm wc xargs

Kills all process that belongs to the user that runs it - excluding bash, sshd (so putty/ssh session will be spared). The bit that says grep -vE "..." can be extended to include ps line patterns that you want to spare.

If no process can be found on the hitlist, it will print # NOTHING TO KILL. Otherwise, it will print # KILL EM ALL, with the cull list.

for _a in {A..Z} {a..z};do _z=\${!${_a}*};for _i in `eval echo "${_z}"`;do echo -e "$_i: ${!_i}";done;done|cat -Tsv

This uses some tricks I found while reading the bash man page to enumerate and display all the current environment variables, including those not listed by the 'env' command which according to the bash docs are more for internal use by BASH. The main trick is the way bash will list all environment variable names when performing expansion on ${!A*}. Then the eval builtin makes it work in a loop.

I created a function for this and use it instead of env. (by aliasing env).

This is the function that given any parameters lists the variables that start with it. So 'aae B' would list all env variables starting wit B. And 'aae {A..Z} {a..z}' would list all variables starting with any letter of the alphabet. And 'aae TERM' would list all variables starting with TERM.

aae(){ local __a __i __z;for __a in "$@";do __z=\${!${__a}*};for __i in `eval echo "${__z}"`;do echo -e "$__i: ${!__i}";done;done; }

And my printenv replacement is:

alias env='aae {A..Z} {a..z} "_"|sort|cat -v 2>&1 | sed "s/\\^\\[/\\\\033/g"'

From: http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html

cat /proc/version
cat /etc/*-release
diff <(ssh [email protected] cat /path/to/file) <(ssh [email protected] cat /path/to/file2)
cat > /dev/null
2010-10-08 14:35:25
User: GouNiNi
Functions: cat

In exemple, screen can bind keys to switch between windows. I like to use Ctrl + Arrow to move left or right window. So I bind like this in .screenrc :

bindkey ^[OD prev # Ctl-left, prev window

bindkey ^[OC next # Ctl-right, next window

cat dvd_output/Layer0/IMAGE.DAT dvd_output/Layer1/IMAGE.DAT > dvd.iso
2010-10-07 18:47:39
User: clintmiller
Functions: cat

This will you combine the DDP output of DVD Studio Pro back into a standard ISO disk image so that you can double-check the DDP output process.

export GREP_COLOR='1;32'; cat /dev/urandom | hexdump -C | grep --color=auto "ca fe"
cat /dev/urandom | hexdump -C | grep "ca fe"
2010-09-27 08:20:44
Functions: cat grep hexdump

just make some data scrolling off the terminal. wow.

cat /proc/cpuinfo
ps -a |grep cat |wc -l
pdftk input.pdf cat 1-endE output output.pdf
package=$1; list=/var/lib/dpkg/info/${package}.list; inst=$(stat "$list" -c %X); cat $list | (while read file; do if [ -f "$file" ];then acc=$(stat "$file" -c %X); if [ $inst -lt $acc ]; then echo used $file; exit 0; fi; fi; done; exit 1)
2010-09-20 18:10:19
User: pipeliner
Functions: cat echo exit read stat
Tags: apt dpkg date stat

This script compares the modification date of /var/lib/dpkg/info/${package}.list and all the files mentioned there.

It could be wrong on noatime partitions.

Here is non-oneliner:




inst=$(stat "$list" -c %X);

cat $list |


while read file; do

if [ -f "$file" ]; then

acc=$(stat "$file" -c %X);

if [ $inst -lt $acc ]; then

echo used $file

exit 0




exit 1


cat VIDEO_TS/VTS_01_[1234].VOB | nice ffmpeg -i - -s 512x384 -vcodec libtheora -acodec libvorbis ~/Videos/dvd_rip.ogg
2010-09-14 14:45:27
User: zhangweiwu
Functions: cat nice
Tags: ffmpeg dvd

To rip DVD movie to ogg format using ffmpeg, follow these steps.

1) find the vob files on the mounted video DVD in VIDEO_TS that stores the movie itself. There would be a few other VOB files that stores splash screen or special features, the vob files for the movie itself can be identified by its superior size. You can verify these vob files by playing them directly with a player (e.g. mplayer)

2) concatenate all such vob files, pipe to ffmpeg

3) calculate the video size and crop size. The ogg video size must be multiple of 16 on both width and height, this is inherit limitation of theora codec. In my case I took 512x384.

The -vcodec parameter is necessary because ffmpeg doesn't support theora by itself. -acodec is necessary otherwise ffmpeg uses flac by default.

pdftk pdfname.pdf cat 1E output outputname.pdf
while [[ COUNTER -le 10 && IFS=':' ]]; do for LINE in $(cat /tmp/list); do some_command(s) $LINE; done; COUNTER=$((COUNTER+1)); done
2010-09-01 15:09:59
User: slashdot
Functions: cat

At times I find that I need to loop through a file where each value that I need to do something with is not on a separate line, but rather separated with a ":" or a ";". In this instance, I create a loop within which I define 'IFS' to be something other than a whitespace character. In this example, I iterate through a file which only has one line, and several fields separated with ":". The counter helps me define how many times I want to repeat the loop.

pdftk first.pdf second.pdf cat output output.pdf
wget http://forums.dropbox.com && wget $(cat index.html|grep "Latest Forum Build"|cut -d"\"" -f2) && wget $(cat topic.php*|grep "Linux x86:"|cut -d"\"" -f2|sort -r|head -n1) && rm -rf ~/.dropbox* && rm index.html *.php* && tar zxvf dropbox-*.tar.gz -C ~/
cat b1.avi b2.avi b3.avi b4.avi b5.avi b6.avi b7.avi > output.avi; mencoder -forceidx -oac copy -ovc copy output.avi -o output_final.avi; rm output.avi
cat | bash
2010-08-18 13:47:46
User: glaudiston
Functions: cat

Sometimes you don't want to leave history, because of passwords use or somethink like.

I think it help.

cls(){ printf "\033c";} or, if no printf, cat > c ;<ctrl+v> <ctrl+[>c <enter><ctrl-d> c(){ cat c;} #usage: c
cat $(ls -c | grep ogg | tac ) > directory/test.ogg