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 ascii from sorted by
Terminal - Commands tagged ascii - 31 results
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
6

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 -n text | hexdump -C
2014-02-21 09:15:15
User: Tomofumi
Functions: echo hexdump
Tags: sed hex ascii
0

hexdump could be used for conversion too!

wget -qO - http://www.asciiartfarts.com/random.cgi | sed -n '/<pre>/,/<\/pre>/p' | sed -n '/<table*/,/<\/table>/p' | sed '1d' | sed '$d' | recode html..ascii
alias html2ascii='lynx -force_html -stdin -dump -nolist'
man ascii
2012-01-26 20:39:13
User: titan2x
Functions: man
0

It shows the complete ascii table, and it works in BSD too, not only in Linux.

showkey -a
perl -e "binmode(STDOUT, ':utf8'); print \"$@\""; echo # newline
2012-01-02 10:34:51
User: mathias
Functions: echo perl
0

This is especially useful to get crazy stuff like space characters copied to your pasteboard correctly.

Source: https://github.com/mathiasbynens/dotfiles/blob/master/.functions

python -c 'print "hello".encode("hex")'
2011-12-13 23:05:17
User: atoponce
Functions: python
2

You can use "decode()" in a similar manner:

python -c 'print "68656c6c6f".decode("hex")'
xxd -p <<< <STRING>
files=(/usr/share/cowsay/cows/*); cowsay -f `echo ${files[$((RANDOM%${#files}))]}` `fortune` | toilet -F gay -f term
2011-02-20 05:55:33
User: lkjoel
-2

This command will tell you your fortune, with a nice Ascii Art animal, and it is colorized

You need cowsay, toilet and fortune installed.

On Ubuntu this is:

sudo apt-get install cowsay toilet fortune

Debian:

aptitude install cowsay toilet fortune
while [ 1 ]; do clear; echo 'YOUR TEXT HERE' | figlet -f banner -t | while IFS="\n" read l; do echo "$l"; sleep 0.01; done; done
2011-02-13 18:52:39
User: lkjoel
Functions: banner echo read sleep
-3

Change YOUR TEXT HERE to the text you want.

On figlet -f banner, you can change it to any figlet font you have installed.

One variant for Star Wars fans could be this:

while [ 1 ]; do clear; echo 'Star Wars' | figlet -f starwars -t | while IFS="\n" read l; do echo "$l"; sleep 0.01; done; done

NOTICE: You need to install figlet.

On Ubuntu, this command is:

sudo apt-get install figlet

On Debian, this command is:

aptitude install figlet
cowsay -l | sed '1d;s/ /\n/g' | while read f; do cowsay -f $f $f;done
echo "text" | hd
echo -n "text" | od -A n -t x1 |sed 's/ /\\x/g'
2010-07-14 15:31:36
User: camocrazed
Functions: echo od sed
Tags: sed hex ascii od
4

If you're going to use od, here's how to suppress the labels at the beginning. Also, it doesn't output the \x, hence the sed command at the end. Remove it for space separated hex values instead

echo "text" | od -t x1
2010-07-14 14:53:25
User: max_allan
Functions: echo od
Tags: perl hex ascii
0

Just use "od" and it can also dump in decimal or octal.

(use -t x1 and not just -x or it confuses the byte order)

There is a load of other formatting options, I'm not sure if you can turn off the address at the start of the line.

echo -n 'text' | perl -pe 's/(.)/sprintf("\\x%x", ord($1))/eg'
2010-07-14 12:20:42
User: putnamhill
Functions: echo perl
Tags: perl hex ascii
1

Here's a version that uses perl. If you'd like a trailing newline:

perl -pe 's/(.)/sprintf("\\x%x", ord($1))/eg; END {print "\n"}'
echo -n 'text' | xxd -ps | sed 's/[[:xdigit:]]\{2\}/\\x&/g'
2010-07-13 21:46:30
User: camocrazed
Functions: echo sed
Tags: sed hex ascii
0

Same as another one I saw, just with a cleaner sed command

Edit: updated the sed command to use the [[:xdigit:]] character class - more portable between locales

Note that it will have a newline inserted after every 32 characters of input, due to the output of xxd

figlet gunslinger_
echo -n 'text' | xxd -ps | sed -e ':a' -e 's/\([0-9]\{2\}\|^\)\([0-9]\{2\}\)/\1\\x\2/;ta'
2010-06-09 12:20:02
User: sata
Functions: echo sed
Tags: hex ascii
1

Converts the ascii text to hex from bash.

Check the sample output.

files=(/usr/share/cowsay/cows/*);cowsay -f `printf "%s\n" "${files[RANDOM % ${#files}]}"` "`fortune`"
2010-06-02 14:18:28
User: dog
0

Can be installed in the root crontab if you want it to update your motd.

If not on ubuntu you need to change /usr/share/cowsay/cows/* to the location of your cow files.

echo $ascii | perl -ne 'printf "%x", ord for split //'
echo $ascii | perl -ne 'printf ("%x", ord($1)) while(/(.)/g); print "\n";'
echo $hex | perl -pe 's/(..)/chr(hex($1))/ge'
while [ 1 ]; do banner 'ze missiles, zey are coming! ' | while IFS="\n" read l; do echo "$l"; sleep 0.01; done; done
2009-12-14 07:40:07
User: craigds
Functions: banner echo read sleep
10

Displays a scrolling banner which loops until you hit Ctrl-C to terminate it.

Make sure you finish your banner message with a space so it will loop nicely.

sed -r "s/\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g
2009-11-03 00:34:06
User: vaejovis
Functions: sed
4

Removes ANSI color and end of line codes to the [{attr1};...;{attrn}m format.