.colors linux
2015-09-02 15:37:57 huyanjie0327 阅读数 129
export LS_OPTIONS='--color=auto'
eval "`dircolors`"
alias ls='ls $LS_OPTIONS'
2019-07-03 00:30:16 weixin_34146410 阅读数 9
less -r

  

grep pattern file.txt --color=always | less -r

  

转载于:https://www.cnblogs.com/long123king/p/3820417.html

2013-05-16 22:31:27 brfeng 阅读数 501
Linux在终端出输出颜色  
   
   
  #include   <stdio.h>;  
   
  int  
  main   (int   argc,   char   **argv)  
  {  
                  printf   ("\033[31mThe   color   of   this   line   is   red,   %s!\033[0m",   "ha   ha");  
  }  
   
   
  格式:   echo   "\033[字背景颜色;字体颜色m字符串\033[0m"  
   
  例如:  
  echo   "\033[41;36m   something   here   \033[0m"  
   
  其中41的位置代表底色,   36的位置是代表字的颜色  
   
   
  那些ascii   code   是对颜色调用的始末.  
  \033[   ;   m   ……   \033[0m  
   
   
   
  字背景颜色范围:40----49  
  40:黑  
  41:深红  
  42:绿  
  43:黄色  
  44:蓝色  
  45:紫色  
  46:深绿  
  47:白色  
   
  字颜色:30-----------39  
  30:黑  
  31:红  
  32:绿  
  33:黄  
  34:蓝色  
  35:紫色  
  36:深绿  
  37:白色  
   
  ===============================================ANSI控制码的说明  
  \33[0m   关闭所有属性  
  \33[1m   设置高亮度  
  \33[4m   下划线  
  \33[5m   闪烁  
  \33[7m   反显  
  \33[8m   消隐  
  \33[30m   --   \33[37m   设置前景色  
  \33[40m   --   \33[47m   设置背景色  
  \33[nA   光标上移n行  
  \33[nB   光标下移n行  
  \33[nC   光标右移n行  
  \33[nD   光标左移n行  
  \33[y;xH设置光标位置  
  \33[2J   清屏  
  \33[K   清除从光标到行尾的内容  
  \33[s   保存光标位置  
  \33[u   恢复光标位置  
  \33[?25l   隐藏光标  
  \33[?25h   显示光标
 
阅读(247) | 评论(0) | 转发(0) |
0

上一篇:Bash 字符串

下一篇:kernel_debug

给主人留下些什么吧!~~
评论热议
2011-01-18 11:31:00 alipro 阅读数 214

If you've just begun programming on the Linux console, you may find yourself less than enthused about the available color choices (or lack thereof). Indeed, the default -- dreary gray on black -- brings to mind Henry Ford's famous statement regarding color schemes for his Model T: "You can have any color you want, as long as it's black."

You may have noticed that the "ls" command is capable of producing a rainbow of colors; executables are typically green, compressed files are red, and graphics (.GIF, .JPG, etc.) are purple.

But are these special hues limited to file listings? If not, how can you apply the day-glo treatment to your own code?

The answer is surprisingly simple: all you need are some console escape sequences.

Try typing the following at your command prompt:

   echo -e "/033[35;1m Shocking /033[0m"
What you should have is the word "Shocking" appearing in bright purple. (Sorry, electric pink is not an option).

This is made possible by /033 , the standard console "escape" code, which is equivalent to ^[ , or 0x1B in hex. When this character is received, the Linux console treats the subsequent characters as a series of commands. These commands can do any number of neat tricks, including changing text colors.

Here's the actual syntax:

   /033 [ <command> m
(In practice, you can't have any spaces between the characters; I've just inserted them here for clarity).

Anything following the trailing "m" is considered to be text. It doesn't matter if you leave a space behind the "m" or not.

So this is how you turn your text to a deep forest green:

   echo -e "/033[32mRun, forest green, run."
Note that the "-e" argument to "echo" turns on the processing of backslash-escaped characters; without this, you'd just see the full string of text in gray, command characters and all. Finally, the command "0" turns off any colors or otherwise funkified text:
   /033[0m
Without the "0" command, your output will continue to be processed, like so:
   echo -e "/033[32mThis is green."

   echo "And so is this."

   echo "And this."

   echo -e "/033[0mNow we're back to normal."
Running a command that uses console colors (e.g., ls) will also reset the console to the standard gray on black.

 

 

Programming Console Colors

Of course, escape sequences aren't limited to shell scripts and functions. Let's see how the same result can be achieved with C and Perl:

C:
   printf("/033[34mThis is blue./033[0m/n");

Perl:
   print "/033[34mThis is blue./033[0m/n";
Trivial, isn't it?

 

Available Colors

Now, how do you know which codes do what? The first eight basic EGA colors are defined as follows:
   30    black foreground
   31    red foreground
   32    green foreground
   33    brown foreground
   34    blue foreground
   35    magenta (purple) foreground
   36    cyan (light blue) foreground
   37    gray foreground
So, if I wanted the word "ocean" to appear in light blue, I could type the following:
   echo -e "The /033[36mocean/033[0m is deep."

 

 

Combining Commands

Multiple console codes can be issued simultaneously by using a semicolon (";"). One useful command is "1", which sets text to bold. The actual effect is a lighter shade of the chosen color. So, to get a light magenta (purple) as shown in the first example, you would do this:
   echo -e "/033[35;1mCombining console codes/033[0m"
This bolding feature allows you to access the other half of the standard 16 EGA colors. Most notably, brown turns into yellow, and gray turns into bright white. The other six colors are just brighter versions of their base counterparts.

 

 

Backgrounds

Text backgrounds can also be set with console codes, allowing you to have white on top of red (for example). Here is the full list of available background options:
   40    black background
   41    red background
   42    green background
   43    brown background
   44    blue background
   45    magenta background
   46    cyan background
   47    white background
What do you think this does?
   echo -e "/033[45;37mGrey on purple./033[0m"
Finally, here are some other noteworthy command codes:
   0     reset all attributes to their defaults
   1     set bold
   5     set blink
   7     set reverse video
   22    set normal intensity
   25    blink off
   27    reverse video off

 

 

Conclusion

And now you have the answer to boring, plain ol' console text. A splash of color can liven up almost any display, creating better aesthetics as well as improving the overall feel.

Unfortunately, these techniques are limited to the console, as they don't display over telnet (unless the remote interface is also a Linux console).

Note that the codes given here are known as ECMA-48 compliant. That is, they work on systems other than Linux. (In case you're interested, ECMA is the European Computer Manufacturers Association, a standards body similar to the ISO). Any system with a VT-102 capable console can use the color codes demonstrated above.

 

Related Resources

1. ECMA This is the page that covers Standard ECMA-48, "Control Functions for Coded Character Sets".

2. "man console_codes" The console_codes man page contains substantial information on not only ECMA-48 compliant codes, but the Linux-specific ones as well.

3. The Linux Documentation Project The LDP is a vast storehouse of Linux-related knowledge.

 

About Author

Jay Link is twentysomething and lives in Springfield, Illinois. Aside from Linux, his interests include mountain climbing and flying. He administrates InterLink BBS (an unintentionally not-for-profit Internet provider) in his fleeting spare moments, as well as working various odd jobs to pay the rent.

2013-03-08 14:50:21 Aegeaner 阅读数 5910

在 Linux 下若想输出 类似与 Windows 下的多颜色字体如何做呢?本文就来介绍实现的方法。

首先,来看下 在Linux 下颜色的表示

All the colors that I have found are:
\033[22;30m - black
\033[22;31m - red
\033[22;32m - green
\033[22;33m - brown
\033[22;34m - blue
\033[22;35m - magenta
\033[22;36m - cyan
\033[22;37m - gray
\033[01;30m - dark gray
\033[01;31m - light red
\033[01;32m - light green
\033[01;33m - yellow
\033[01;34m - light blue
\033[01;35m - light magenta
\033[01;36m - light cyan
\033[01;37m - white

可以看出都是使用的转义字体来实现的。这时就好办了撒。

比如:

  Linux 终端输入:echo -e  "\033[35;1m Shocking \033[0m"

  C代码:                printf("\033[34mThis is blue.\033[0m\n");

是不是出错不同的颜色了,记得最后要 "\033[0m"  关闭所有属性,这样又回到了系统默认的颜色了。

没有更多推荐了,返回首页