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.


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:



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.




Commands using echo from sorted by
Terminal - Commands using echo - 1,210 results
echo `date +%m/%d/%y%X |awk '{print $1;}' `" => "` cat /proc/acpi/thermal_zone/THRM/temperature | awk '{print $2, $3;}'` >> datetmp.log
2009-08-24 21:26:29
User: ninadsp
Functions: awk cat echo

Uses the data in the /proc system, provided by the acpid, to find out the CPU temperature. Can be run on systems without lm-sensors installed as well.

y=http://www.youtube.com;for i in $(curl -s $f|grep -o "url='$y/watch?v=[^']*'");do d=$(echo $i|sed "s|url\='$y/watch?v=\(.*\)&.*'|\1|");wget -O $d.flv "$y/get_video.php?video_id=$d&t=$(curl -s "$y/watch?v=$d"|sed -n 's/.* "t": "\([^"]*\)",.*/\1/p')";done
2009-08-22 21:31:29
User: matthewbauer
Functions: echo grep sed

This will download a Youtube playlist and mostly anything http://code.google.com/apis/youtube/2.0/reference.html#Video_Feeds

The files will be saved by $id.flv

pgrep -u `id -u` firefox-bin || find ~/.mozilla/firefox -name '*.sqlite'|(while read -e f; do echo 'vacuum;'|sqlite3 "$f" ; done)
2009-08-22 10:36:05
User: kamathln
Functions: echo find read

Sqlite database keeps collecting cruft as time passes, which can be cleaned by the 'vacuum;' command. This command cleans up the cruft in all sqlite files relating to the user you have logged in as. This command has to be run when firefox is not running, or it will exit displaying the pid of the firefox running.

for u in `cut -f1 -d: /etc/passwd`; do echo -n $u:; groups $u; done | sort
2009-08-22 09:06:02
User: hemanth
Functions: echo groups
Tags: sort cut for groups

"cut" the user names from /etc/passwd and then running a loop over them.

echo $(( $RANDOM % 10 + 1 ))
echo init 0 | at now + 2 hours
echo "scale=4; 3 / 5" | bc
2009-08-21 21:51:46
User: foob4r
Functions: echo

allows you to use floating point operations in shell scripts

sync; echo 3 > /proc/sys/vm/drop_caches
watch() { t=$1; shift; while test :; do clear; date=$(date); echo -e "Every "$t"s: $@ \t\t\t\t $date"; $@; sleep $t; done }
watch() { while test :; do clear; date=$(date); echo -e "Every "$1"s: $2 \t\t\t\t $date"; $2; sleep $1; done }
echo sleep() begins: %TIME% && FOR /l %a IN (10,-1,1) do (ECHO 1 >NUL %as&ping -n 2 -w 1>NUL) && echo sleep() end: %TIME%
2009-08-19 13:43:09
User: pfredrik
Functions: echo

Enable 'sleep' function in Windows environment where this does not exist, although not exact in time. (there is a delay for each ping) This is a simple way to separate commands with a time-period.

S=$SSH_TTY && (sleep 3 && echo -n 'Peace... '>$S & ) && (sleep 5 && echo -n 'Love... '>$S & ) && (sleep 7 && echo 'and Intergalactic Happiness!'>$S & )
2009-08-19 07:57:16
User: AskApache
Functions: echo sleep

Ummmm.. Saw that gem on some dead-head hippies VW bus at phish this summer.. It's actually one of my favorite ways of using bash, very clean. It shows what you can do with the cool advanced features like job control, redirection, combining commands that don't wait for each other, and the thing I like the most is the use of the ( ) to make this process heirarchy below, which comes in very handy when using fifos for adding optimization to your scripts or commands with similar acrobatics.


1 gplovr 30667 1 wait 1324 1 -bash

0 gplovr 30672 30667 - 516 3 \_ sleep 3

1 gplovr 30669 1 wait 1324 1 -bash

0 gplovr 30673 30669 - 516 0 \_ sleep 5

1 gplovr 30671 1 wait 1324 1 -bash

0 gplovr 30674 30671 - 516 1 \_ sleep 7

echo "nohup command rm -rf /phpsessions 1>&2 &>/dev/null 1>&2 &>/dev/null&" | at now + 3 hours 1>&2 &>/dev/null
2009-08-18 07:31:17
User: AskApache
Functions: at echo

This is helpful for shell scripts, I use it in my custom php install script to schedule to delete the build files in 3 hours, as the php install script is completely automated and is made to run slow.

Does require at, which some environments without crontab still do have.

You can add as many commands to the at you want. Here's how I delete them in case the script gets killed. (trapped)

atq |awk '{print $1}'|xargs -iJ atrm J &>/dev/null

urls=('www.ubuntu.com' 'google.com'); for i in ${urls[@]}; do http_code=$(curl -I -s $i -w %{http_code}); echo $i status: ${http_code:9:3}; done
echo "import this" | python
2009-08-15 09:42:36
User: loquitus
Functions: echo

Very very cool list of quotations and directives on pythonic programming. I love them and they are sure applicable in C++ too, and for most any programming, really.

$(while [ ! -z "$(pgrep rsync)" ]; do echo; done; echo "rsync done" | mailx user@example.com) > /dev/null &
2009-08-14 19:46:59
User: matthewbauer
Functions: echo mailx

This will email user@example.com a message with the body: "rsync done" when there are no processes of rsync running. This can be changed for other uses by changing $(pgrep rsync) to something else, and echo "rsync done" | mailx user@example.com to another command.

echo $PATH|awk -F: ' { for (i=1; i <= NF; i++) print $i }'
echo "<?php phpinfo(); ?>" >> /srv/www/htdocs/test.php
wget http://checkip.dyndns.org && clear && echo && echo My IP && egrep -o '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}' index.html && echo && rm index.html
ips(){ for if in ${1:-$(ip link list|grep '^.: '|cut -d\ -f2|cut -d: -f1)};do cur=$(ifconfig $if|grep "inet addr"|sed 's/.*inet addr:\([0-9\.]*\).*/\1/g');printf '%-5s%-15s%-15s\n' $if $cur $(nc -s $cur sine.cluenet.org 128 2>/dev/null||echo $cur);done;}
2009-08-07 10:04:46
User: frozenfire
Functions: cut echo grep ifconfig link sed

Gets the internal and external IP addresses of all your interfaces, or the ones given as arguments

echo "Body goes here" | mutt -s "A subject" -a /path/to/file.tar.gz recipient@example.com
2009-08-05 23:06:25
User: ketil
Functions: echo

This command uses mutt to send the mail. You must pipe in a body, otherwise mutt will prompt you for some stuff. If you don't have mutt, it should be dead easy to install.

echo <ctrl-v><esc>c<enter>
2009-08-05 18:32:28
User: kcm
Functions: echo

This works in some situations where 'reset' and the other alternatives don't.

echo linux|rev
2009-08-04 12:28:44
Functions: echo
Tags: rev


rev - reverse lines of a file or files


rev [file ...]


The rev utility copies the specified files to the standard output, reversing the order of characters in every line. If no files are specified, the standard input is read.


The rev command is part of the util-linux-ng package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.

copy(){ cp -v "$1" "$2"&watch -n 1 'du -h "$1" "$2";printf "%s%%\n" $(echo `du -h "$2"|cut -dG -f1`/0.`du -h "$1"|cut -dG -f1`|bc)';}
tmpfile=$(mktemp) && echo -e 'startup_message off\nscreen -t top htop\nsplit\nfocus\nscreen -t nethogs nethogs wlan0\nsplit\nfocus\nscreen -t iotop iotop' > $tmpfile && sudo screen -c $tmpfile
2009-08-03 10:14:02
User: Patola
Functions: echo screen sudo top

This command starts screen with 'htop', 'nethogs' and 'iotop' in split-screen. You have to have these three commands (of course) and specify the interface for nethogs - mine is wlan0, I could have acquired the interface from the default route extending the command but this way is simpler.

htop is a wonderful top replacement with many interactive commands and configuration options. nethogs is a program which tells which processes are using the most bandwidth. iotop tells which processes are using the most I/O.

The command creates a temporary "screenrc" file which it uses for doing the triple-monitoring. You can see several examples of screenrc files here: http://www.softpanorama.org/Utilities/Screen/screenrc_examples.shtml