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 tagged echo from sorted by
Terminal - Commands tagged echo - 80 results
printf -vl "%${COLUMNS:-`tput cols 2>&-||echo 80`}s\n" && echo ${l// /-};
2016-09-25 10:37:20
User: AskApache
Functions: echo printf

Unlike other methods that use pipes and exec software like tr or sed or subshells, this is an extremely fast way to print a line and will always be able to detect the terminal width or else defaults to 80. It uses bash builtins for printf and echo and works with printf that supports the non-POSIX `-v` option to store result to var instead of printing to stdout.

Here it is in a function that lets you change the line character to use and the length with args, it also supports color escape sequences with the echo -e option.

function L() { local l=; builtin printf -vl "%${2:-${COLUMNS:-`tput cols 2>&-||echo 80`}}s\n" && echo -e "${l// /${1:-=}}"; }

With color:

L "`tput setaf 3`="

1. Use printf to store n space chars followed by a newline to an environment variable "l" where n is local environment variable from $COLUMNS if set, else it will use `tput cols` and if that fails it will default to 80.

2. If printf succeeds then echo `$l` that contains the chars, replacing all blank spaces with "-" (can be changed to anything you want).

From: http://www.askapache.com/linux/bash_profile-functions-advanced-shell.html http://www.askapache.com/linux/bash-power-prompt.html

echo "obase=2;$((($(date +%s)-$(date +%s -d YYYY-MM-DD))/86400))" | bc
2015-10-19 15:40:32
User: flatcap
Functions: echo

Print out your age in days in binary.

Today's my binary birthday, I'm 2^14 days old :-)


This command does bash arithmatic $(( )) on two dates:

Today: $(date +%s)

Date of birth: $(date +%s -d YYYY-MM-DD)

The dates are expressed as the number of seconds since the Unix epoch (Jan 1970),

so we devide the difference by 86400 (seconds per day).


Finally we pipe "obase=2; DAYS-OLD" into bc to convert to binary.

(obase == output base)

echo "DISPLAY=$DISPLAY xmessage call the client" | at 10:00
2015-05-01 14:57:15
User: op4
Functions: at echo
Tags: echo at xmessage

This command will create a popup reminder window to assist in remembering tasks

http://i.imgur.com/2n7viiA.png is how it looks when created

wget -q -O "quote" https://www.goodreads.com/quotes_of_the_day;notify-send "$(echo "Quote of the Day";cat quote | grep '&ldquo;\|/author/show' | sed -e 's/<[a-zA-Z\/][^>]*>//g' | sed 's/&ldquo;//g' | sed 's/&rdquo;//g')"; rm -f quote
2014-06-15 03:17:19
User: nowhereman88
Functions: rm wget

Just pulls a quote for each day and displays it in a notification bubble...

or you can change it a bit and just have it run in the terminal

wget -q -O "quote" https://www.goodreads.com/quotes_of_the_day;echo "Quote of the Day";cat quote | grep '&ldquo;\|/author/show' | sed -e 's/<[a-zA-Z\/][^>]*>//g' | sed 's/&ldquo;//g' | sed 's/&rdquo;//g'; rm -f quote
for i in {1..256};do p=" $i";echo -e "${p: -3} \\0$(($i/64*100+$i%64/8*10+$i%8))";done|cat -t|column -c120
2014-04-04 16:54:53
User: AskApache
Functions: cat column echo

Prints out an ascii chart using builtin bash! Then formats using cat -t and column.

The best part is:

echo -e "${p: -3} \\0$(( $i/64*100 + $i%64/8*10 + $i%8 ))";

From: http://www.askapache.com/linux/ascii-codes-and-reference.html

echo "Hello WOrld"
2013-11-24 10:26:50
User: Abhay_k
Functions: echo
Tags: echo

This will display --> Hello World

echo 0$(awk '/Pss/ {printf "+"$2}' /proc/$PID/smaps)|bc
2013-09-26 18:20:22
User: atoponce
Functions: awk echo
Tags: Linux awk echo bc proc

The "proportional set size" is probably the closest representation of how much active memory a process is using in the Linux virtual memory stack. This number should also closely represent the %mem found in ps(1), htop(1), and other utilities.

echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile
2013-09-19 03:25:14
Functions: echo

If the HISTTIMEFORMAT is set, the time stamp information associated with each history entry is written to the history file, marked with the history comment character.

color () { local color=39; local bold=0; case $1 in green) color=32;; cyan) color=36;; blue) color=34;; gray) color=37;; darkgrey) color=30;; red) color=31;; esac; if [[ "$2" == "bold" ]]; then bold=1; fi; echo -en "\033[${bold};${color}m"; }
printTextInColorRed () { echo -e '\033[01;31m\033[K'"$@"'\033[m\033[K' ;} ## print text/string in color red
2013-08-28 10:06:59
User: totti
Functions: echo


printTextInColorRed foo bar

foo bar [in red color]

echo -e "CHECK=SAMPLE" output --command_to_long
2013-04-03 08:46:47
User: techie
Functions: echo

This is longer than others on here. The reason for this is I have combined two different matrix commands so it would work on all computers. I logged onto my server through a computer and it worked fine. I logged into my server through a mac and it looked $4!t so I have made one that works through both.

centralized(){ L=`echo -n $*|wc -c`; echo -e "\x1b[$[ ($COLUMNS / 2) - ($L / 2) ]C$*"; }
2012-08-16 18:19:26
User: xenomuta
Functions: echo wc
Tags: echo ansi

Echoes text horizontally centralized based on screen width

echo 00:29:36 | sed s/:/*60+/g | bc
for i in /var/spool/cron/tabs/*; do echo ${i##*/}; sed 's/^/\t/' $i; echo; done
2012-07-12 08:07:20
User: harpo
Functions: echo sed

This is flatcaps tweaked command to make it work on SLES 11.2

for i in /var/spool/cron/*; do echo ${i##*/}; sed 's/^/\t/' $i; echo; done
alias tail='tail -n $((${LINES:-`tput lines 2>/dev/null||echo -n 80`} - 7))'
2012-03-22 02:44:11
User: AskApache
Functions: alias echo

Run the alias command, then issue

ps aux | tail

and resize your terminal window (putty/console/hyperterm/xterm/etc) then issue the same command and you'll understand.

${LINES:-`tput lines 2>/dev/null||echo -n 12`}

Insructs the shell that if LINES is not set or null to use the output from `tput lines` ( ncurses based terminal access ) to get the number of lines in your terminal. But furthermore, in case that doesn't work either, it will default to using the default of 80.

The default for TAIL is to output the last 10 lines, this alias changes the default to output the last x lines instead, where x is the number of lines currently displayed on your terminal - 7. The -7 is there so that the top line displayed is the command you ran that used TAIL, ie the prompt.

Depending on whether your PS1 and/or PROMPT_COMMAND output more than 1 line (mine is 3) you will want to increase from -2. So with my prompt being the following, I need -7, or - 5 if I only want to display the commandline at the top. ( http://www.askapache.com/linux/bash-power-prompt.html )


[7995:7993 - 0:186] 06:26:49 Thu Apr 08 [[email protected]:/dev/pts/0 +1] ~

In most shells the LINES variable is created automatically at login and updated when the terminal is resized (28 linux, 23/20 others for SIGWINCH) to contain the number of vertical lines that can fit in your terminal window. Because the alias doesn't hard-code the current LINES but relys on the $LINES variable, this is a dynamic alias that will always work on a tty device.

sayspeed() { for i in $(seq 1 `echo "$1"|wc -c`); do echo -n "`echo $1 |cut -c ${i}`"; sleep 0.1s; done; echo "";}
2012-02-11 05:51:42
User: kundan
Functions: echo seq sleep wc

change the time that you would like to have as print interval

and just use it to say whatever you want to

ping1 IPaddr_or_hostname
2012-02-09 17:26:32
User: waibati
Tags: echo IP ping

export THISOS="`uname -s`"

if [ "$THISOS" = "SunOS" ]


export THISRELEASE="`uname -r`"

ping1() { ping -s $1 56 1 | egrep "^64"; }

elif [ "$THISOS" = "AIX" ]


export THISRELEASE="`uname -v`.`uname -r`"

ping1() { ping -w ${2:-1} $1 56 1 | egrep "^64"; }

elif [ "$THISOS" = "Linux" ]


export THISRELEASE="`uname -r`"

ping1() { ping -c 1 -w ${2:-1} $1 | egrep "^64"; }


echo -n "IP Address or Machine Name: "; read IP; ping -c 1 -q $IP >/dev/null 2>&1 && echo -e "\e[00;32mOnline\e[00m" || echo -e "\e[00;31mOffline\e[00m"
2012-02-09 07:00:03
User: crlf
Functions: echo ping read
Tags: bash echo IP ping

I have used single packet, and in a silent mode with no display of ping stats. This is with color and UI improvement to the http://www.commandlinefu.com/commands/view/10220/check-if-a-machine-is-online. It is as per the enhancements suggested.

ping -c 1 -q MACHINE_IP_OR_NAME >/dev/null 2>&1 && echo ONLINE || echo OFFLINE
2012-02-09 06:30:55
User: UnixNeko
Functions: echo ping
Tags: echo IP ping



c 1 limits to 1 pinging attempt

q makes the command quiet (or silent mode)

/dev/null 2>&1 is to remove the display

&& echo ONLINE is executed if previous command is successful (return value 0)

|| echo OFFLINE is executed otherwise (return value of 1 if unreachable or 2 if you're offline yourself).

I personally use this command as an alias with a predefined machine name but there are at least 2 improvements that may be done.

Asking for the machine name or IP

Escaping the output so that it displays ONLINE in green and OFFLINE in red (for instance).

genRandomText() { a=( a b c d e f g h i j k l m n o p q r s t u v w x y z );f=0;for i in $(seq 1 $(($1-1))); do r=$(($RANDOM%26)); if [ "$f" -eq 1 -a $(($r%$i)) -eq 0 ]; then echo -n " ";f=0;continue; else f=1;fi;echo -n ${a[$r]};done;echo"";}
2012-01-20 21:18:16
User: bbbco
Functions: echo seq

Ever need to get some text that is a specific number of characters long? Use this function to easily generate it! Doesn't look pretty, but sure does work for testing purposes!

for file in * .*; do echo $PWD/$file; done
2011-12-16 13:42:07
User: marek158
Functions: echo file
Tags: echo ls

Also lists hidden files, current dir and topdir.

for file in *; do echo $PWD/$file; done
echo -n "password"|md5sum|awk '{print $1}'
2011-11-08 21:34:50
User: windfold
Functions: awk echo

This is mostly for my own notes but this command will compute a md5 message digest from the command line.

You can also replace md5sum with other checksum commands (e.g., sha1sum)

date -ud "1970/01/01 00:29:36" +%s
2011-11-01 17:02:46
User: frans
Functions: date
Tags: echo date time

uses the -u switch for UTC

Another way could be

echo $(($(date -ud "00:29:36" +%s)%86400))