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.

Universal configuration monitoring and system of record for IT.
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

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!
Hide

Top Tags

Hide

Functions

Hide

Credits

Commands using echo from sorted by
Terminal - Commands using echo - 1,288 results
box() { t="$1xxxx";c=${2:-=}; echo ${t//?/$c}; echo "$c $1 $c"; echo ${t//?/$c}; }
2010-02-26 13:17:12
User: bartonski
Functions: echo
6

First argument: string to put a box around.

Second argument: character to use for box (default is '=')

Same as command #4948, but shorter, and without the utility function.

box() { l=${#1}+4;x=${2:-=};n $l $x; echo "$x $1 $x"; n $l $x; }; n() { for (( i=0; $i<$1; i=$i+1)); do printf $2; done; printf "\n"; }
2010-02-26 06:56:59
User: bartonski
Functions: echo printf
1

The function 'box' takes either one or two arguments. The first argument is a line of text to be boxed, the second argument (optional) is a character to use to draw the box. By default, the drawing character will be '='.

The function 'n()' is a helper function used to draw the upper and lower lines of the box, its arguments are a length, and an character to print. (I used 'n' because 'line', 'ln' and 'l' are all commonly used)

underline() { echo $1; for (( i=0; $i<${#1}; i=$i+1)); do printf "${2:-=}"; done; printf "\n"; }
2010-02-26 05:46:49
User: bartonski
Functions: echo printf
1

underline() will print $1, followed by a series of '=' characters the width of $1. An optional second argument can be used to replace '=' with a given character.

This function is useful for breaking lots of data emitted in a for loop into sections which are easier to parse visually. Let's say that 'xxxx' is a very common pattern occurring in a group of CSV files.

You could run

grep xxxx *.csv

This would print the name of each csv file before each matching line, but the output would be hard to parse visually.

for i in *.csv; do printf "\n"; underline $i; grep "xxxx" $i; done

Will break the output into sections separated by the name of the file, underlined.

echo -e "Some Text Line1\nSome Text Line 2" | convert -background none -density 196 -resample 72 -unsharp 0x.5 -font "Courier" text:- -trim +repage -bordercolor white -border 3 text.gif
2010-02-25 18:58:42
User: glaudiston
Functions: echo
16

generates a picture file with the text.

Some other samples in:

http://www.imagemagick.org/Usage/text/

echo "pretty realistic virtual typing" | randtype -m 4
2010-02-25 15:30:28
User: tehdog
Functions: echo
4

this also generates errors (change 4 to higher number for more mistakes)

{ u="http://twitter.com/commandlinefu"; echo "Subject: $u"; echo "Mime-Version: 1.0"; echo -e "Content-Type: text/html; charset=utf-8\n\n"; curl $u ; } | sendmail recipient@example.com
2010-02-24 04:18:30
User: pascalv
Functions: echo sendmail
-1

This will send the web page at $u to recipient@example.com . To send the web page to oneself, recipient@example.com can be replaced by $(whoami) .

The "charset" is UTF-8 here, but any alternative charset of your choice would work.

`wget -O - -o /dev/null $u` may be considered instead of `curl $u` .

On some systems the complete path to sendmail may be necessary, for instance /sys/pkg/libexec/sendmail/sendmail for some NetBSD.

echo "Starting Daemon"; ( while :; do sleep 15; echo "I am still running =]"; done ) & disown -h $!
2010-02-23 19:17:05
User: daleki
Functions: echo sleep
-2

You don't want the -ar parameters in this case. The man page for BASH_BUILTINS(1) states:

"-a option means to remove or mark all jobs" and

"-r option without a jobspec argument restricts operation to running jobs"

In this case we are supplying the process id of the job to disown so neither of these should be used.

echo 0 >/selinux/enforce
2010-02-17 16:33:26
User: svnlabs
Functions: echo
-7

just change SELINUX=enforcing to SELINUX=permissive, and you're done. Reboot if you want to prove it.

spellcheck(){ typeset y=$@;curl -sd "<spellrequest><text>$y</text></spellrequest>" https://www.google.com/tbproxy/spell|sed -n '/s="[0-9]"/{s/<[^>]*>/ /g;s/\t/ /g;s/ *\(.*\)/Suggestions: \1\n/g;p}'|tee >(grep -Eq '.*'||echo -e "OK");}
2010-02-17 08:20:48
User: eightmillion
Functions: echo grep sed tee
5

I took matthewbauer's cool one-liner and rewrote it as a shell function that returns all the suggestions or outputs "OK" if it doesn't find anything wrong. It should work on ksh, zsh, and bash. Users that don't have tee can leave that part off like this:

spellcheck(){ typeset y=$@;curl -sd "<spellrequest><text>$y</text></spellrequest>" https://google.com/tbproxy/spell|sed -n '/s="[1-9]"/{s/<[^>]*>/ /g;s/\t/ /g;s/ *\(.*\)/Suggestions: \1\n/g;p}';}
for domain in `cat list_of_domains.txt`; do echo $domain; whois $domain >> output.txt; done
2010-02-15 17:13:45
User: pathcl
Functions: echo whois
-2

Outputs multiple whois from a plain text file.

for i in `ndd /dev/ip \? | awk '{ print $1 }' | egrep -v "ip6|status|icmp|igmp|\?"` ; do echo $i `ndd -get /dev/ip $i` ; done | grep -v \?
2010-02-15 12:32:33
User: felix001
Functions: awk echo egrep grep
0

This command is jsut for the main IP settings of ndd. if you need ip6 or icmp edit the text within the egrep inclusion area.

Felix001 - www.Fir3net.com

uri_escape(){ echo -E "$@" | sed 's/\\/\\\\/g;s/./&\n/g' | while read -r i; do echo $i | grep -q '[a-zA-Z0-9/.:?&=]' && echo -n "$i" || printf %%%x \'"$i" done }
2010-02-13 01:39:51
User: infinull
Functions: echo grep printf read sed
1

This one uses hex conversion to do the converting and is in shell/sed only (should probably still use the python/perl version).

echo "$url" | perl -MURI::Escape -ne 'chomp;print uri_escape($_),"\n"'
2010-02-13 00:44:48
User: eightmillion
Functions: echo perl
Tags: perl
5

Converts reserved characters in a URI to their percent encoded counterparts.

Alternate python version:

echo "$url" | python -c 'import sys,urllib;print urllib.quote(sys.stdin.read().strip())'
echo "$@" | sed 's/ /%20/g;s/!/%21/g;s/"/%22/g;s/#/%23/g;s/\$/%24/g;s/\&/%26/g;s/'\''/%27/g;s/(/%28/g;s/)/%29/g;s/:/%3A/g'
echo $(cat file)
smenu() ( IFS=',' ; select x in $*; do echo "$x" | xsel -i; done )
2010-02-08 15:33:53
User: bartonski
Functions: echo
Tags: xsel select
2

The function will take a comma separated list of items to be 'selected' by xsel -i:

smenu "First item to paste,Paste me #2,Third menu item"

You will then be prompted to choose one of the menu items. After you choose, you will be able to paste the string by clicking the middle mouse button.

The menu will keep prompting you to choose menu items until you break out with Control-C.

echo "I'm going to paste this into WINDERS XP" | xsel -i
2010-02-08 00:23:43
User: bartonski
Functions: echo
Tags: X xsel putty XMing
4

Set up X forwarding in PuTTY, with X display location set to :0.0

Launch PuTTY ssh session.

Launch Xming. Make sure that display is set to :0.0 (this is default).

echo "I'm going to paste this into WINDERS XP" | xsel -i

will insert the string into the windows cut and paste buffer.

Thanks to Dennis Williamson at stackoverflow.com for sharing...

echo "There are $(($(date +%j -d"Dec 31, $(date +%Y)")-$(date +%j))) left in year $(date +%Y)."
/bin/bash echo -n "Let's POST MORE, PLEASE!"
2010-02-05 18:52:45
User: editorreilly
Functions: echo
-15

I absolutely love this website, and appreciate every contribution. This is the first place I go when I'm stuck, you all have some great ideas. But contributions seem to be slipping a little. If all of us could contribute more code from time to time, this site would be absolutely incredible. Since I'm a relative newcomer to commandline-fu, I don't have the knowledge to contribute much, but I will do what I can.

newest () { DIR=${1:-'.'}; CANDIDATE=`find $DIR -type f|head -n1`; while [[ ! -z $CANDIDATE ]]; do BEST=$CANDIDATE; CANDIDATE=`find $DIR -newer "$BEST" -type f|head -n1`; done; echo "$BEST"; }
2010-02-04 12:40:44
User: shadycraig
Functions: echo head
1

Works recusivley in the specified dir or '.' if none given.

Repeatedly calls 'find' to find a newer file, when no newer files exist you have the newest.

In this case 'newest' means most recently modified. To find the most recently created change -newer to -cnewer.

echo '.dump' | sqlite3 your_sqlite.db > your_sqlite_text.txt
2010-02-04 07:58:41
User: alamati
Functions: echo
4

If you want edit your sqlite database in any uft8 supported editor, you can dump whole sqlite database to plain text.

echo {1..199}" bottles of beer on the wall, cold bottle of beer, take one down, pass it around, one less bottle of beer on the wall,, " | espeak -v english -s 140
2010-02-04 04:38:52
User: op4
Functions: echo
21

you know the song... sing along

echo "DISPLAY=$DISPLAY xmessage setup suphp perms htscanner acct#101101 host2.domain.com" | at 23:00 Feb 8
2010-02-04 04:26:24
User: op4
Functions: at echo
1

setup for reminder in 5 days, added the date in the future. To run a job at 4pm three days from now, you would do at 4pm + 3 days, to run a job at 10:00am on July 31, you would do at 10am Jul 31 and to run a job at 1am tomorrow, you would do at 1am tomorrow.

echo "DISPLAY=$DISPLAY xmessage convert db to innodb" | at 00:00
while read l; do echo $RANDOM "$l"; done | sort -n | cut -d " " -f 2-
2010-02-03 22:36:34
User: ketil
Functions: cut echo read sort
0

If you need to randomize the lines in a file, but have an old sort commands that doesn't support the -R option, this could be helpful. It's easy enough to remember so that you can create it as a script and use that.

It ain't real fast. It ain't safe. It ain't super random. Do not use it on untrusted data. It requires bash for the $RANDOM variable to work.