Hide

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.

Hide

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands tagged tee from sorted by
Terminal - Commands tagged tee - 29 results
w !sudo cat >%
command_line 2>&1 | tee -a output_file
alias t="tee >(pbcopy)"
2014-01-24 12:41:07
User: lgarron
Functions: alias
0

Very convenient to for sending data to the clipboard for processing.

However, note that tee will affect the buffering of the output (stdout won't be update very live).

ssh USER@HOST cat REMOTE_FILE.mp4 | tee LOCAL_FILE.mp4 | mplayer -
2013-11-28 11:25:26
User: flatcap
Functions: cat ssh tee
6

Securely stream a file from a remote server (and save it locally).

Useful if you're impatient and want to watch a movie immediately and download it at the same time without using extra bandwidth.

This is an extension of snipertyler's idea.

Note: This command uses an encrypted connection, unlike the original.

nc HOST PORT | tee movie.mp4 | mplayer -
2013-11-28 01:38:29
User: snipertyler
Functions: tee
7

Requires a listening port on HOST

eg. "cat movie.mp4 | nc -l 1356 " (cat movie.mp4 | nc -l PORT)

Useful if you're impatient and want to watch a movie immediately and download it at the same time without using extra bandwidth.

You can't seek (it'll crash and kill the stream) but you can pause it.

dd if=file | tee >(sha1sum) >(md5sum) >(sha256sum) >/dev/null
2013-11-07 17:43:54
User: dubbaluga
Functions: dd tee
Tags: tee parallel I/O
0

This is to overcome the issue of slow I/O by reading once and forwarding the output to several processes (e. g. 3 in the given command). One could also invoke grep or other programs to work on read data.

script -qf | tee >(nc -l -p 5000)
echo 'foo' | tee >(wc -c) >(grep o) >(grep f)
2013-01-31 09:54:18
User: totti
Functions: echo grep tee wc
Tags: tee output input
5

Output of a command as input to many

COMMAND - OPTIONS - MORE OPTIONS | tee >> /file/you/want_to_append_output_to
cmdfu(){ local t=~/cmdfu;echo -e "\n# $1 {{{1">>$t;curl -s "commandlinefu.com/commands/matching/$1/`echo -n $1|base64`/plaintext"|sed '1,2d;s/^#.*/& {{{2/g'>$t;vim -u /dev/null -c "set ft=sh fdm=marker fdl=1 noswf" -M $t;rm $t; }
2012-02-21 05:43:16
User: AskApache
Functions: echo rm sed vim
6

Here is the full function (got trunctated), which is much better and works for multiple queries.

function cmdfu () {

local t=~/cmdfu;

until [[ -z $1 ]]; do

echo -e "\n# $1 {{{1" >> $t;

curl -s "commandlinefu.com/commands/matching/$1/`echo -n $1|base64`/plaintext" | sed '1,2d;s/^#.*/& {{{2/g' | tee -a $t > $t.c;

sed -i "s/^# $1 {/# $1 - `grep -c '^#' $t.c` {/" $t;

shift;

done;

vim -u /dev/null -c "set ft=sh fdm=marker fdl=1 noswf" -M $t;

rm $t $t.c

}

Searches commandlinefu for single/multiple queries and displays syntax-highlighted, folded, and numbered results in vim.

curl -s ifconfig.me|tee >(xargs geoiplookup)
2012-02-09 20:30:26
Functions: tee xargs
Tags: tee curl geoip
0

Show external IP and geolocation information.

Primary feature is the use of tee to echo IP _and_ send to geoiplookup command...Use IP as input for as many commands as you want with more >( [command] )

Thanks to http://www.commandlinefu.com/commands/view/6334/

Requires MaxMind DB and geoiplookup tool.

Sample output has IP obfuscated on first line, lines 2-4 from having MaxMind Country && MaxMind City DBs installed

:w!
command W :execute ':silent w !sudo tee % > /dev/null' | :edit!
2011-10-06 20:37:54
Functions: command tee
Tags: vim sudo tee
7

Calls sudo tee like all the other lines, but also automatically reloads the file.

Optionally you can add

command Wq :execute ':W' | :q

and

command WQ :Wq

to make quitting easier

sudo find / -type f | perl -MFile::Basename -ne '$counts{dirname($_)}++; END { foreach $d (sort keys %counts) {printf("%d\t%s\n",$counts{$d},$d);} }'|sort -rn | tee /tmp/sortedfilecount.out | head
2011-09-14 19:41:19
User: tamouse
Functions: find perl sort sudo tee
0

Find which directories on your system contain a lot of files.

Edit: much shorter and betterer with -n switch.

(set -e; while true; do TEST_COMMAND; done) | tee log
2011-09-06 12:29:11
User: wipu
Functions: set tee
Tags: tee while set
-3

If you need to fix a randomly failing test (race condition), you need to run it until you get that hard-to-reproduce failure.

:%!sudo tee %
2011-06-17 07:16:23
User: antone
Functions: tee
Tags: vim sudo tee
1

probably just like 1204, but uses tee as a filter (+ I actually understand how this one works)

mkdir copy{1,2}; gzip -dc file.tar.gz | tee >( tar x -C copy1/ ) | tar x -C copy2/
2011-04-14 17:02:05
User: depesz
Functions: gzip mkdir tar tee
Tags: bash tee tar
-1

Sometimes you might need to have two copies of data that is in tar. You might unpack, and then copy, but if IO is slow, you might lower it by automatically writing it twice (or more times)

script -qf | tee >(nc -kl 5000) >(nc -kl 5001) >(nc -kl 5002)
2010-10-11 07:55:30
User: clvv
Functions: script tee
Tags: tee pipe script nc
37

run 'nc yourip 5000', 'nc yourip 5001' or 'nc yourip 5002' elsewhere will produce an exact same mirror of your shell. This is handy when you want to show someone else some amazing stuff in your shell without giving them control over it.

echo "uptime" | tee >(ssh host1) >(ssh host2) >(ssh host3)
echo "tee can split a pipe in two"|tee >(rev) >(tr ' ' '_')
2010-08-14 20:38:59
User: axelabs
Functions: echo tee tr
33

Tee can be used to split a pipe into multiple streams for one or more process to work it. You can add more " >()" for even more fun.

if test -w $1; then vim $1; else sudo vim $1; fi
2010-08-14 13:28:32
User: srepmub
Functions: sudo test vim
Tags: vim sudo tee
-2

this avoids several VIM warnings, which I seem too stupid to disable: warning, readonly! and: file and buffer have changed, reload?!

tee >(cat - >&2)
2010-07-20 17:22:31
User: camocrazed
Functions: cat tee
5

the tee command does fine with file names, but not so much with file descriptors, such as &2 (stderr). This uses process redirection to tee to the specified descriptor.

In the sample output, it's being used to tee to stderr, which is connected with the terminal, and to wc -l, which is also outputting to the terminal. The result is the output of bash --version followed by the linecount

:w !sudo tee > /dev/null %
2010-03-24 20:04:26
User: idemal
Functions: tee
Tags: vim sudo tee
24

Write a file you edited in Vim but that you do not have the permissions to write to (unless you use sudo.) Same as #1204 but without the echo to stdout that I find annoying.

dd if=/dev/sda | tee >(dd of=/dev/sdb) | dd of=/dev/sdc
2009-12-11 17:34:38
User: nerd65536
Functions: dd tee
Tags: bash tee dd pipe root
21

If you have some drive imaging to do, you can boot into any liveCD and use a commodity machine. The drives will be written in parallel.

To improve efficiency, specify a larger block size in dd:

dd if=/dev/sda bs=64k | tee >(dd of=/dev/sdb bs=64k) | dd of=/dev/sdc bs=64k

To image more drives , insert them as additional arguments to tee:

dd if=/dev/sda | tee >(dd of=/dev/sdb) >(dd of=/dev/sdc) >(dd of=/dev/sdd) | dd of=/dev/sde
cat /path/to/some/file.txt | tee /dev/pts/0 | wc -l
2009-11-07 22:24:28
User: atoponce
Functions: cat tee wc
Tags: tee
2

This is a cool trick to view the contents of the file on /dev/pts/0 (or whatever terminal you're using), and also send the contents of that file to another program by way of an unnamed pipe. All the while, you've not bothered saving any extra data to disk, like you might be tempted to do with sed or grep to filter output.