Java
SSH and SCP
Linux
- Linux console Colors And Other Trick's By Jay Link
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";
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
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
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.
In short, something is wrong with if condition, it is expecting a single value but gets multiple values.
This can be done using either the groups command or the id command.
Use one of the greps (grep, egrep, fgrep). You want to use the -r "recursive" option to search a directory and all files included within it.
grep -r -i ONOCR /usr/include [nsl@nsl]$ grep -r -i ONOCR /usr/include /usr/include/asm/termbits.h:#define ONOCR 0000020 /usr/include/linux/cdk.h:#define FO_ONOCR 0x8 /usr/include/linux/tty.h:#define O_ONOCR(tty) _O_FLAG((tty),ONOCR) /usr/include/bits/termios.h:#define ONOCR 0000020
The '-i' means ignore case. So if you only wanted it in all capitals you would not use it. When used it will find any combination of upper and lower case.