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

Show numerical values for each of the 256 colors in bash

Terminal - Show numerical values for each of the 256 colors in bash
for code in {0..255}; do echo -e "\e[38;05;${code}m $code: Test"; done
2010-06-19 02:14:42
User: scribe
Functions: echo
40
Show numerical values for each of the 256 colors in bash

Same as http://www.commandlinefu.com/commands/view/5876, but for bash.

This will show a numerical value for each of the 256 colors in bash. Everything in the command is a bash builtin, so it should run on any platform where bash is installed. Prints one color per line. If someone is interested in formatting the output, paste the alternative.

Alternatives

There are 2 alternatives - vote for the best!

Terminal - Alternatives
for i in {0..255}; do echo -e "\e[38;05;${i}m${i}"; done | column -c 80 -s ' '; echo -e "\e[m"
2010-07-21 17:30:36
User: cout
Functions: column echo
8

I like the other three versions but one uses nested loops and another prints every color on a separate line. Both versions fail to reset colors before giving the prompt back.

This version uses the column command to print a table so all the colors fit on one screen. It also resets colors back to normal before as a last step.

for code in {000..255}; do print -P -- "$code: %F{$code}Test%f"; done
2010-06-18 22:19:49
User: atoponce
Tags: zsh
2

This will show a numerical value for each of the 256 colors in ZSH. Everything in the command is a ZSH builtin, so it should run on any platform where ZSH is installed. Prints one color per line. If someone is interested in formatting the output, paste the alternative.

for code in $(seq -w 0 255); do for attr in 0 1; do printf "%s-%03s %bTest%b\n" "${attr}" "${code}" "\e[${attr};38;05;${code}m" "\e[m"; done; done | column -c $((COLUMNS*2))
2013-01-13 18:23:44
User: claudius
Functions: column printf seq
Tags: bash color colors
0

Shows the ?rendering? for each of the 256 colours in both the bold and normal variant. Using seq is helpful to get even lines, passing $((COLUMNS*2)) to column sort-of-handles the nonprintable characters.

for i in {0..255}; do echo -e "\e[38;05;${i}m\\\e[38;05;${i}m"; done | column -c 80 -s ' '; echo -e "\e[m"
2013-07-05 07:16:19
User: derv82
Functions: column echo
Tags: zsh
0

Prints an easy-to-copy color code for each color.

Know a better way?

If you can do better, submit your command here.

What others think

hmm, needs to set a background color so it doesn't blend in so badly with my shell's bg color.

Comment by kaedenn 219 weeks and 1 day ago

I'd echo the code itself rather than "Test".

See http://www.pixelbeat.org/scripts/ansi_colours.sh

For a 256 color palette you can hover over to get the code see:

http://www.pixelbeat.org/docs/terminal_colours/#256

Comment by pixelbeat 219 weeks ago

More compact output all on one line:

for code in {0..255}; do echo -en "\e[38;05;${code}m $code:"; done
Comment by dattaway 218 weeks and 5 days ago

The pretty part of the table, nicely formatted:

for line in {0..5}; do for col in {0..39}; do code=$(( $col * 6 + $line + 16 )); printf $'\e[38;05;%dm %03d' $code $code ;done; echo ;done
Comment by bartonski 217 weeks ago

Your point of view

You must be signed in to comment.

Related sites and podcasts