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 tee from sorted by
Terminal - Commands using tee - 98 results
gate() { mkfifo /tmp/sock1 /tmp/sock2 &> /dev/null && nc -p $1 -l < /tmp/sock1 | tee /tmp/sock2 & PID=$! && nc $2 $3 < /tmp/sock2 | tee /tmp/sock1; kill -KILL $PID; rm -f /tmp/sock1 /tmp/sock2 ; }
2009-09-25 08:10:23
User: true
Functions: kill mkfifo rm tee

USAGE: gate listening_port host port

Creates listening socket and connects to remote device at host:port. It uses pipes for connection between two sockets. Traffic which goes through pipes is wrote to stdout. I use it for debug network scripts.

(some_command 2>&1 1>&3 | tee /path/to/errorlog ) 3>&1 1>&2 | tee /path/to/stdoutlog
bash -x test.sh 2>&1 | tee out.test
2009-09-03 17:10:44
User: arcege
Functions: bash tee

Sends both stdout and stderr to the pipe which captures the data in the file 'out.test' and sends to stdout of tee (likely /dev/tty unless redirected). Works on Bourne, Korn and Bash shells.

watch -n 0.5 ssh [user]@[host] mysqladmin -u [mysql_user] -p[password] processlist | tee -a /to/a/file
2009-08-19 14:21:27
User: lunarblu
Functions: ssh tee watch

Locally watch MySQL process list update every 5s on a remote host. While you watch pipe to a file. The file out put is messy though but hey at least you have a history of what you see.

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.

echo "Hello World." | tee -a hello.txt
2009-06-26 00:55:59
Functions: echo tee
Tags: tee

When plumbers use pipes, they sometimes need a T-joint. The Unix equivalent to this is 'tee'. The -a flag tells 'tee' to append to the file, rather than clobbering it.

Tested on bash and tcsh.

ssh -i $PRIVATEKEY $HOST -C 'cd $SOURCE; tar -cz --numeric-owner .' | tee $DESTINATION/backup.tgz | tar -tz
2009-05-18 20:36:45
User: GeckoDH
Functions: ssh tar tee
PRIVATEKEY - Of course the full path to the private key \n HOST - The host where to get the backup \n SOURCE - The directory you wish to backup \n DESTINATION - The destination for the backup on your local machine
script /dev/null | tee /dev/pts/3
2009-04-19 00:29:45
Functions: script tee

can display the commands and their output to another user who is connected to another terminal, by example pts/3

ssh [email protected] | tee logfilename
2009-04-17 19:17:02
User: bassu
Functions: ssh tee

Optionally, you can create a new function to do this with a custom command. Edit $HOME/.bashrc and add:

myssh () { ssh $1 | tee sshlog ; }

Save it.

At command prompt:

myssh [email protected]
shuf -n1 /usr/share/dict/words | tee >(sed -e 's/./&\n/g' | shuf | tr -d '\n' | line) > /tmp/out
< /dev/urandom tr -dc A-Za-z0-9_ | head -c $((1024 * 1024)) | tee >(gzip -c > out.gz) >(bzip2 -c > out.bz) > /dev/null
rev <<< 'lorem ipsum' | tee /dev/stderr | rev
2009-03-31 13:12:09
User: penpen
Functions: rev tee
Tags: Linux unix

In the above example 'muspi merol' (the output of the first rev command) is sent to stderr and 'lorem ipsum' (the output of the second rev command) is sent to stdout. rev reverse lines of a file or files. This use of tee allows testing if a program correctly handles its input without using files that hold the data.

sudo find / -iname "*.lproj" -and \! -iname "en*" -print0 | tee /dev/stderr | sudo xargs -0 rm -rfv
2009-03-09 22:08:45
User: asmoore82
Functions: find rm sudo tee xargs

This will get the job done in the most efficient way -

spawning only one `rm` process.

"On-the-fly" find data is displayed through `tee` and

you should have plenty of time to ctrl-c if needed before it's too late.

You may need to re-run this after major Software Updates.

To leave more languages in, add more ``-and \! -iname "lang*"'' statements:

sudo find / -iname "*.lproj" -and \! -iname "en*" -and \! -iname "spanish*" -print0 | tee /dev/stderr | sudo xargs -0 rm -rfv

**Edit: note the 2nd sudo near the end of the pipeline - this is necessary.

echo "Whatever you need" | sudo tee [-a] /etc/system-file.cfg
2009-03-09 01:33:31
User: asmoore82
Functions: echo sudo tee

only for sudo-style systems.

Use this construct instead of I/O re-directors ``>'' or ``>>'' because

sudo only elevates the commands and *not* the re-directors.

***warning: remember that the `tee` command will clobber

file contents unless it is given the ``-a'' argument

Also, for extra security, the "left" command is still run unprivileged.

dd if=/dev/cdrom | pv -s 700m | md5sum | tee test.md5
2009-03-09 00:11:42
User: asmoore82
Functions: dd md5sum tee

[re]verify those burned CD's early and often - better safe than sorry -

at a bare minimum you need the good old `dd` and `md5sum` commands,

but why not throw in a super "user-friendly" progress gauge with the `pv` command -

adjust the ``-s'' "size" argument to your needs - 700 MB in this case,

and capture that checksum in a "test.md5" file with `tee` - just in-case for near-future reference.

*uber-bonus* ability - positively identify those unlabeled mystery discs -

for extra credit, what disc was used for this sample output?

some_cronjobed_script.sh 2>&1 | tee -a output.log | grep -C 1000 ERROR
2009-03-06 17:51:13
User: DEinspanjer
Functions: grep tee
Tags: Linux

The large context number (-C 1000) is a bit of a hack, but in most of my use cases, it makes sure I'll see the whole log output.

somecommand 2>&1 >> logfile | tee -a logfile
2009-03-04 15:15:05
User: operon
Functions: tee

Useful for cron jobs -- all output will be logged but only errors will cause email to be sent. NB the order of "2>&1" and ">> logfile" is important, it doesn't work if you reverse them (everything goes to the logfile, nothing left for tee).

mkfifo /tmp/fifo; cat /tmp/fifo | nc -l -p 1234 | tee -a to.log | nc machine port | tee -a from.log > /tmp/fifo
2009-02-20 04:00:15
User: prutser
Functions: cat mkfifo tee

Forwards localhost:1234 to machine:port, running all data through your chain of piped commands. The above command logs inbound and outbound traffic to two files.

Tip: replace tee with sed to manipulate the data in real time (use "sed -e 's/400 Bad Request/200 OK/'" to tweak a web server's responses ;-) Limitless possibilities.

echo "foo bar" | sudo tee -a /path/to/some/file
2009-02-18 13:54:25
User: raphink
Functions: echo sudo tee

This is the solution to the common mistake made by sudo newbies, since

sudo echo "foo bar" >> /path/to/some/file

does NOT add to the file as root.


sudo echo "foo bar" > /path/to/some/file

should be replaced by

echo "foo bar" | sudo tee /path/to/some/file

And you can add a >/dev/null in the end if you're not interested in the tee stdout :

echo "foo bar" | sudo tee -a /path/to/some/file >/dev/null
some_command | tee >(command1) >(command2) >(command3) ... | command4
2009-02-17 01:55:07
User: SiegeX
Functions: tee

Using process substitution, we can 'trick' tee into sending a command's STDOUT to an arbitrary number of commands. The last command (command4) in this example will get its input from the pipe.

find . -type f -exec grep -l XXX {} \;|tee /tmp/fileschanged|xargs perl -pi.bak -e 's/XXX/YYY/g'
2009-02-16 02:55:23
User: drossman
Functions: find grep perl tee xargs

Find all files that contain string XXX in them, change the string from XXX to YYY, make a backup copy of the file and save a list of files changed in /tmp/fileschanged.

ping google.com | tee ping-output.txt
2009-01-29 10:26:59
User: root
Functions: ping tee

The tee (as in "T" junction) command is very useful for redirecting output to two places.