Commands tagged color (58)


  • 67
    tr -c "[:digit:]" " " < /dev/urandom | dd cbs=$COLUMNS conv=unblock | GREP_COLOR="1;32" grep --color "[^ ]"
    allinurl · 2009-06-30 17:23:49 23
  • 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.


    49
    for code in {0..255}; do echo -e "\e[38;05;${code}m $code: Test"; done
    scribe · 2010-06-19 02:14:42 13
  • Get your colorized grep output in less(1). This involves two things: forcing grep to output colors even though it's not going to a terminal and telling less to handle those properly.


    32
    grep --color=always | less -R
    dinomite · 2009-05-20 20:30:19 12
  • I like the fact the Patola's version uses only ones and zeros, but I also like the sparse output of the other versions. This one combines both of those features and eliminates some unnecessary cruft. You can vary the sparseness by changing "$(($RANDOM % 5))" to another number. The number in this term "$(($RANDOM % 4))" controls how frequently the numbers are output bold.


    21
    echo -e "\e[32m"; while :; do for i in {1..16}; do r="$(($RANDOM % 2))"; if [[ $(($RANDOM % 5)) == 1 ]]; then if [[ $(($RANDOM % 4)) == 1 ]]; then v+="\e[1m $r "; else v+="\e[2m $r "; fi; else v+=" "; fi; done; echo -e "$v"; v=""; done
    dennisw · 2009-09-27 15:30:38 16
  • in case you run some command in CLI and would like to take read strerr little bit better, you can use the following command. It's also possible to grep it if necessary....


    19
    mycommand 2> >(while read line; do echo -e "\e[01;31m$line\e[0m"; done)
    confiq · 2010-12-30 21:42:42 19

  • 18
    yes "$(seq 232 255;seq 254 -1 233)" | while read i; do printf "\x1b[48;5;${i}m\n"; sleep .01; done
    frans0023 · 2009-07-03 13:58:02 9
  • I've been using linux for almost a decade and only recently discovered that most terminals like putty, xterm, xfree86, vt100, etc., support hundreds of shades of colors, backgrounds and text/terminal effects. This simply prints out a ton of them, the output is pretty amazing. If you use non-x terminals all the time like I do, it can really be helpful to know how to tweak colors and terminal capabilities. Like: echo $'\33[H\33[2J'


    17
    for c in `seq 0 255`;do t=5;[[ $c -lt 108 ]]&&t=0;for i in `seq $t 5`;do echo -e "\e[0;48;$i;${c}m|| $i:$c `seq -s+0 $(($COLUMNS/2))|tr -d '[0-9]'`\e[0m";done;done
    AskApache · 2009-11-03 09:12:13 9
  • Simple way to achieve a colored SVN diff


    16
    svn diff <file> | vim -R -
    caiosba · 2009-06-13 22:00:49 69
  • Add the followin to ~/.bashrc #colour export LESS_TERMCAP_mb=$'\E[01;31m' export LESS_TERMCAP_md=$'\E[01;37m' export LESS_TERMCAP_me=$'\E[0m' export LESS_TERMCAP_se=$'\E[0m' export LESS_TERMCAP_so=$'\E[01;44;33m' export LESS_TERMCAP_ue=$'\E[0m' export LESS_TERMCAP_us=$'\E[01;32m'


    15
    echo "export LESS_TERMCAP_mb=$'\E[01;31m'" >> ~/.bashrc
    totti · 2011-10-20 17:34:14 8

  • 10
    color()(set -o pipefail;"$@" 2>&1>&3|sed $'s,.*,\e[31m&\e[m,'>&2)3>&1
    bkmeneguello · 2013-01-30 13:42:03 7
  • 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.


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

  • 8
    COL=$(( $(tput cols) / 2 )); clear; tput setaf 2; while :; do tput cup $((RANDOM%COL)) $((RANDOM%COL)); printf "%$((RANDOM%COL))s" $((RANDOM%2)); done
    sputnick · 2009-12-15 02:48:28 10
  • Solves "tr" issues with non C-locales under BSD-like systems (like OS X)


    7
    LC_ALL=C tr -c "[:digit:]" " " < /dev/urandom | dd cbs=$COLUMNS conv=unblock | GREP_COLOR="1;32" grep --color "[^ ]"
    zzambia · 2009-07-02 07:10:33 11
  • This will create a permanent alias to colorize the search pattern in your grep output


    7
    echo alias grep=\'grep --color=auto\' >> ~/.bashrc ; . ~/.bashrc
    0x2142 · 2009-07-05 07:44:13 7
  • This is super fast and an easy way to test your terminal for 256 color support. Unlike alot of info about changing colors in the terminal, this uses the ncurses termcap/terminfo database to determine the escape codes used to generate the colors for a specific TERM. That means you can switch your terminal and then run this to check the real output. tset xterm-256color at any rate that is some super lean code! Here it is in function form to stick in your .bash_profile aa_256 () { ( x=`tput op` y=`printf %$((${COLUMNS}-6))s`; for i in {0..256}; do o=00$i; echo -e ${o:${#o}-3:3} `tput setaf $i;tput setab $i`${y// /=}$x; done ) } From my bash_profile: http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html Show Sample Output


    7
    ( x=`tput op` y=`printf %$((${COLUMNS}-6))s`;for i in {0..256};do o=00$i;echo -e ${o:${#o}-3:3} `tput setaf $i;tput setab $i`${y// /=}$x;done; )
    AskApache · 2010-09-06 10:39:27 8
  • This is a simple command, but extremely useful. It's a quick way to search the file names in the current directory for a substring. Normally people use "ls *term*" but that requires the stars and is not case insensitive. Color (for both ls and grep) is an added bonus.


    6
    alias lg='ls --color=always | grep --color=always -i'
    kFiddle · 2009-04-11 23:15:12 8
  • Same as the cool matrix style command ( http://www.commandlinefu.com/commands/view/3652/matrix-style ), except replacing the printed character with randomness. The command mentioned is much faster and thus more true to the matrix. However, mine can be optimized, but I wasted ... i mean spent enough time on it already Show Sample Output


    6
    check the sample output below, the command was too long :(
    pykler · 2009-09-29 19:30:10 135

  • 6
    tail -F file | egrep --color 'pattern|$'
    sklm · 2009-10-16 04:01:14 3
  • It colors the machine name and current directory different colors for easy viewing.


    5
    export PS1='\[\033[0;35m\]\h\[\033[0;33m\] \w\[\033[00m\]: '
    kamiller · 2009-03-18 22:05:48 11
  • Removes ANSI color and end of line codes to the [{attr1};...;{attrn}m format.


    5
    sed -r "s/\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g
    vaejovis · 2009-11-03 00:34:06 6
  • A bit different from some of the other submissions. Has bold and uses all c printable characters. Change the bs=value to speed up and increase the sizes of the bold and non-bold strings.


    5
    echo -ne "\e[32m" ; while true ; do echo -ne "\e[$(($RANDOM % 2 + 1))m" ; tr -c "[:print:]" " " < /dev/urandom | dd count=1 bs=50 2> /dev/null ; done
    psykotron · 2009-12-19 19:05:04 4

  • 4
    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"; }
    zvyn · 2013-09-06 09:37:42 13
  • blue and yellow colored bash prompt for a Hanukkah celebration on your box


    3
    export PS1="\e[0;34m[\u\e[0;34m@\h[\e[0;33m\w\e[0m\e[0m\e[0;34m]#\e[0m "
    decept · 2009-12-13 18:35:06 8
  • Depending on the TERM, the terminfo version, ncurses version, etc.. you may be using a varied assortment of terminal escape codes. With this command you can easily find out exactly what is going on.. This is terminal escape zen! ( 2>&2 strace -f -F -e write -s 1000 sh -c 'echo -e "initc\nis2\ncnorm\nrmso\nsgr0" | tput -S' 2>&1 ) | grep -o '"\\[^"]*"' --color=always "\33]4;%p1%d;rgb:%p2%{255}%*%{1000}%/%2.2X/%p3%{255}%*%{1000}%/%2.2X/%p4%{255}%*%{1000}%/%2.2X\33\\\33[!p\33[?3;4l\33[4l\33>\33[?12l\33[?25h\33[27m\33(B\33[m" Lets say you want to find out what you need to echo in order to get the text to blink.. echo -e "`tput blink`This will blink`tput sgr0` This wont" Now you can use this function instead of calling tput (tput is much smarter for portable code because it works differently depending on the current TERM, and tput -T anyterm works too.) to turn that echo into a much faster executing code. tput queries files, opens files, etc.. but echo is very strait and narrow. So now you can do this: echo -e "\33[5mThis will blink\33(B\33[m This wont" More at http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html Show Sample Output


    3
    termtrace(){( strace -s 1000 -e write tput $@ 2>&2 2>&1 ) | grep -o '"[^"]*"';}
    AskApache · 2010-03-17 08:53:41 7
  • One of my favorite ways to impress newbies (and old hats) to the power of the shell, is to give them an incredibly colorful and amazing version of the top command that runs once upon login, just like running fortune on login. It's pretty sweet believe me, just add this one-liner to your ~/.bash_profile -- and of course you can set the height to be anything, from 1 line to 1000! G=$(stty -g);stty rows $((${LINES:-50}/2));top -n1; stty $G;unset G Doesn't take more than the below toprc file I've added below, and you get all 4 top windows showing output at the same time.. each with a different color scheme, and each showing different info. Each window would normally take up 1/4th of your screen when run like that - TOP is designed as a full screen program. But here's where you might learn something new today on this great site.. By using the stty command to change the terminals internal understanding of the size of your terminal window, you force top to also think that way as well. # save the correct settings to G var. G=$(stty -g) # change the number of rows to half the actual amount, or 50 otherwise stty rows $((${LINES:-50}/2)) # run top non-interactively for 1 second, the output stays on the screen (half at least) top -n1 # reset the terminal back to the correct values, and clean up after yourself stty $G;unset G This trick from my [ http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html bash_profile ], though the online version will be updated soon. Just think what else you could run like this! Note 1: I had to edit the toprc file out due to this site can't handle that (uploads/including code). So you can grab it from [ http://www.askapache.com/linux-unix/bash-power-prompt.html my site ] Note 2: I had to come back and edit again because the links weren't being correctly parsed Show Sample Output


    3
    G=$(stty -g);stty rows $((${LINES:-50}/2));top -n1; stty $G;unset G
    AskApache · 2010-04-22 18:52:49 13
  •  1 2 3 > 

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. 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.

Share Your Commands


Check These Out

securely erase unused blocks in a partition
This command securely erases all the unused blocks on a partition. The unused blocks are the "free space" on the partition. Some of these blocks will contain data from previously deleted files. You might want to use this if you are given access to an old computer and you do not know its provenance. The command could be used while booted from a LiveCD to clear freespace space on old HD. On modern Linux LiveCDs, the "ntfs-3g" system provides ReadWrite access to NTFS partitions thus enabling this method to also be used on Wind'ohs drives. NB depending on the size of the partition, this command could take a while to complete.

Use the builtin ':' bash command to increment variables
I just found another use for the builtin ':' bash command. It increments counters for me in a loop if a certain condition is met... : [arguments] No effect; the command does nothing beyond expanding arguments and performing any specified redirections. A zero exit code is returned.

Gets the last string of previous command with !$
It helps you save a lot of writing :-)

run php code inline from the command line
Most people know that you can run a PHP script from the command line like so: $php ./my_script.php But sometimes I just want to run a quick bit of code, the PHP Command Line Interface allows me to do so with the -r option. Requires package php5-cli

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

Make vim open in tabs by default (save to .profile)
I always add this to my .profile rc so I can do things like: "vim *.c" and the files are opened in tabs.

List your installed Chromium extensions (with url to each page)
Gives you a list for all installed chrome (chromium) extensions with URL to the page of the extension. With this you can easy add a new Bookmark folder called "extensions" add every URL to that folder, so it will be synced and you can access the names from every computer you are logged in. ------------------------------------------------------------------------------------------------------------------ Only tested with chromium, for chrome you maybe have to change the find $PATH.

Commandline document conversion with Libreoffice
In this example, the docx gets converted to Open Document .odt format. For other formats, you'll need to specify the correct filter (Hint: see "Comments" link below for a nice list).

Delete recursively only empty folders on present dir

find which lines in a file are longer than N characters
Filter out lines of input that contain 72, or fewer, characters. This uses bash only. ${#i} is the number of characters in variable i.


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: