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
cat somefile | tee >(openssl md5 > sum.md5) | bzip2 > somefile.bz2
cat myfile | tee dest1 dest2 > /dev/null 2>&1
find . -printf "touch -m -d \"%t\" '%p'\n" | tee /tmp/retime.sh
2012-11-05 20:32:05
User: dmmst19
Functions: find tee

Sometimes when copying files from one place to another, the timestamps get lost. Maybe you forgot to add a flag to preserve timestamps in your copy command. You're sure the files are exactly the same in both locations, but the timestamps of the files in the new home are wrong and you need them to match the source.

Using this command, you will get a shell script (/tmp/retime.sh) than you can move to the new location and just execute - it will change the timestamps on all the files and directories to their previous values. Make sure you're in the right directory when you launch it, otherwise all the touch commands will create new zero-length files with those names. Since find's output includes "." it will also change the timestamp of the current directory.

Ideally rsync would be the way to handle this - since it only sends changes by default, there would be relatively little network traffic resulting. But rsync has to read the entire file contents on both sides to be sure no bytes have changed, potentially causing a huge amount of local disk I/O on each side. This could be a problem if your files are large. My approach avoids all the comparison I/O. I've seen comments that rsync with the "--size-only" and "--times" options should do this also, but it didn't seem to do what I wanted in my test. With my approach you can review/edit the output commands before running them, so you can tell exactly what will happen.

The "tee" command both displays the output on the screen for your review, AND saves it to the file /tmp/retime.sh.

Credit: got this idea from Stone's answer at http://serverfault.com/questions/344731/rsync-copying-over-timestamps-only?rq=1, and combined it into one line.

command 3>&1 1>&2 2>&3 | tee -a file
2012-10-30 15:40:08
User: netkill
Functions: command tee

Appends output to the file, some systems require the -a to do this.

command 3>&1 1>&2 2>&3 | tee file
2012-10-30 10:53:21
User: hute37
Functions: command tee

taken from



What does it mean?

The redirection operator n>&m makes file descriptor n to be a copy of file descriptor m. So, whe are:

- Opening a new file descriptor, 3, that is a copy of file descriptor 1, the standard output;

- Making file descriptor 1 a copy of file descriptor 2, the standard error output;

- Making file descriptor 2 to be a copy of file descriptor 3 (the "backup" of the standard output)

in a short: we swapped the standard output and the standard error output.


COMMAND - OPTIONS - MORE OPTIONS | tee >> /file/you/want_to_append_output_to
echo $(find <directory> -name '*.<extension>' -exec du -s {} \; | tee $(tty) | cut -f1 | tr '\n' '+') 0 | bc
2012-09-17 22:46:50
User: ysangkok
Functions: cut du echo find tee tr

Also shows files as they are found. Only works from a tty.

find . -type f \( -name '*.c' -o -name '*.cpp' -o -name '*.cc' -o -name '*.cxx' \) | xargs grep "#include.*\.c.*" 2>&1 | tee source_inside_source_list.txt
echo "[some repository]" | sudo tee -a /etc/apt/sources.list
2012-04-21 17:54:08
Functions: echo sudo tee

For instance, to add mongodb 10gen package

echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" | sudo tee -a /etc/apt/sources.list

echo mem|sudo tee /sys/power/state
sudo sync && sudo echo 3 | sudo tee /proc/sys/vm/drop_caches
2012-03-17 08:27:58
User: StephenJudge
Functions: echo sudo sync tee
Tags: memory cache

"That's it. Not much to see here. The first command writes any cache data that hasn't been written to the disk out to the disk. The second command tells the kernel to drop what's cached. Not much to it. This invalidates the write cache as well as the read cache, which is why we have the sync command first. Supposedly, it is possible to have some cached write data never make it to disk, so use it with caution, and NEVER do it on a production server. You could ... but why take the risk?

As long as you are running a post 2.6.16 kernel,..."

Source: http://ubuntuforums.org/showpost.php?p=3621283&postcount=1

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

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 sudo tee %
command > >(tee stdout.log) 2> >(tee stderr.log >&2)
sync && echo 3 | sudo tee /proc/sys/vm/drop_caches
command W :execute ':silent w !sudo tee % > /dev/null' | :edit!
2011-10-06 20:37:54
Functions: command tee
Tags: vim sudo tee

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

Optionally you can add

command Wq :execute ':W' | :q


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

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

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

find . -type f | xargs grep -n "Old Text" | tee filesChanged.txt | sed 's/:.*$//' | xargs sed -i 's/Old Text/New Text/g
:%!sudo tee %
2011-06-17 07:16:23
User: antone
Functions: tee
Tags: vim sudo tee

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

echo "GRUB_INIT_TUNE=\"480 440 4 440 4 440 4 349 3 523 1 440 4 349 3 523 1 440 8 659 4 659 4 659 4 698 3 523 1 415 4 349 3 523 1 440 8"\"" | sudo tee -a /etc/default/grub > /dev/null && sudo update-grub
find . -name "*.png" | tee images.txt | grep book
2011-06-02 23:55:50
Functions: find grep tee

You can find every file with png extension and redirect its output to file. Later you can find a string inside the file.

for i in $(find . -name *md5checksum_file* | sed 's/\(\.\/.*\)md5checksum_file.txt/\1/'); do cd "$i"; md5sum -c "md5checksum_file.txt"; cd -; done | tee ~/checksum_results.txt | grep -v "<current directory>"
2011-05-17 01:08:44
User: gocoogs
Functions: cd find grep md5sum sed tee

extracts path to each md5 checksum file, then, for each path, cd to it, check the md5sum, then cd - to toggle back to the starting directory. greps at the end to remove cd chattering on about the current directory.

nohup cat /dev/ttyS0 | tee -a llamadas.db&
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

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)