Difference between revisions of "Bash - Changing the colours"
(16 intermediate revisions by the same user not shown) | |||
Line 9: | Line 9: | ||
[[File:LS COLORS Sampler.png|right|middle|thumb]] | [[File:LS COLORS Sampler.png|right|middle|thumb]] | ||
( # Run in a subshell so it won't crash current color settings dircolors -b >/dev/null | ( | ||
# Run in a subshell so it won't crash current color settings | |||
dircolors -b >/dev/null | |||
IFS=: | IFS=: | ||
for ls_color in ${LS_COLORS[@]}; do # For all colors | for ls_color in ${LS_COLORS[@]}; do # For all colors | ||
Line 22: | Line 24: | ||
You control the colours with an environment variable named '''LS_COLORS''' which you can set in your '''~/.bashrc''' file. (On many Linux variants, you can simply define the variable in a file named '''~/.dircolors''', but not all. So putting it in your '''~/.bashrc''' file is the safest bet.) | You control the colours with an environment variable named '''LS_COLORS''' which you can set in your '''~/.bashrc''' file. (On many Linux variants, you can simply define the variable in a file named '''~/.dircolors''', but not all. So putting it in your '''~/.bashrc''' file is the safest bet.) | ||
* <code>vi .bashrc</code> | * <code>vi ~/.bashrc</code> | ||
& add the following: | & add the following: | ||
# Adjust the LS colours | |||
# Adjust the LS colours | LS_COLORS="'''YOURNEWCOLORS'''" | ||
LS_COLORS= | |||
export LS_COLORS | export LS_COLORS | ||
Line 34: | Line 36: | ||
Then: | Then: | ||
* <code>source .bashrc</code> | * <code>source ~/.bashrc</code> | ||
to enable your changes. | |||
The format of '''YOURNEWCOLORS''' is a colon separated list of key/code sets. & each key/code set consists of a key from the table below followed by 1-3 codes from the second table all separated by semicolons. (I know... weird...) | |||
so: '''key''';'''foreground''';'''background''';'''effect''' | |||
& all but the key are optional. | |||
Any key/code set not specified will be displayed using the default values. | |||
== Examples == | |||
[[File:LS COLORS Example 0.png{{!}}300px{{!}}thumb]] | |||
The default for a directory writable by "other" users hurts me... | |||
So I put '''LS_COLORS="ow=34;43"; '''in my .bashrc file. | |||
MUCH better! | |||
Now I can read it. | |||
[[File:LS COLORS Example 1.png{{!}}300px{{!}}thumb]] | |||
Then I made it '''LS_COLORS="ow=34;43:*.weird=36;04";''' to customise a 'weird' file extension. | |||
= The Details = | |||
== What the codes mean == | == What the codes mean == | ||
Line 366: | Line 394: | ||
<br> | <br> | ||
{{!}}} | {{!}}} | ||
== Handy Links == | |||
* [https://ansi.gabebanks.net/ ANSI escape code generator] | |||
[[Category:Linux]] |
Latest revision as of 17:40, 21 May 2023
Modern Linux & UNIX systems can colourise the output of ls.
Sadly, the default colour choices can make your eyes bleed...
Fortunately, you can customise the colour choices.
To see the default (or, at least, current) colours your system shows for everything, paste the following code block directly at the command line.
( # Run in a subshell so it won't crash current color settings dircolors -b >/dev/null IFS=: for ls_color in ${LS_COLORS[@]}; do # For all colors color=${ls_color##*=} ext=${ls_color%%=*} echo -en "\E[${color}m${ext}\E[0m " # echo color and extension done echo )
LS_COLORS
You control the colours with an environment variable named LS_COLORS which you can set in your ~/.bashrc file. (On many Linux variants, you can simply define the variable in a file named ~/.dircolors, but not all. So putting it in your ~/.bashrc file is the safest bet.)
vi ~/.bashrc
& add the following:
# Adjust the LS colours LS_COLORS="YOURNEWCOLORS" export LS_COLORS
You'll, of course, be replacing YOURNEWCOLORS with codes and colours of your own choosing.
Then:
source ~/.bashrc
to enable your changes.
The format of YOURNEWCOLORS is a colon separated list of key/code sets. & each key/code set consists of a key from the table below followed by 1-3 codes from the second table all separated by semicolons. (I know... weird...)
so: key;foreground;background;effect
& all but the key are optional.
Any key/code set not specified will be displayed using the default values.
Examples
The default for a directory writable by "other" users hurts me...
So I put LS_COLORS="ow=34;43"; in my .bashrc file.
MUCH better!
Now I can read it.
Then I made it LS_COLORS="ow=34;43:*.weird=36;04"; to customise a 'weird' file extension.
The Details
What the codes mean
Key | Defaults | Name | Notes |
|
color:background:effect |
|
|
no |
|
NORMAL, NORM | Global default, although everything should be something |
fi |
|
FILE | Normal file |
di | 01;34 | DIR | Directory |
ln | 01;36 | SYMLINK, LINK, LNK | Symbolic link. If you set this to 'target' instead of a numerical value, the colour is as for the file pointed to. |
pi | 40;33 | FIFO, PIPE | Named pipe |
do | 01;35 | DOOR | Door |
bd | 40;33;01 | BLOCK, BLK | Block device |
cd | 40;33;01 | CHAR, CHR | Character device |
or | 40;31;01 | ORPHAN | Symbolic link pointing to a non-existent file |
so | 01;35 | SOCK | Socket |
su | 37;41 | SETUID | File that is setuid (u+s) |
sg | 30;43 | SETGID | File that is setgid (g+s) |
tw | 30;42 | STICKY_OTHER_WRITABLE | Directory that is sticky and other-writable (+t,o+w) |
ow | 34;42 | OTHER_WRITABLE | Directories that are writeable by other users |
st | 37;44 | STICKY | Directory with the sticky bit set (+t) and not other-writable |
ex | 01;32 | EXEC | Executable file (i.e. has 'x' set in permissions) |
mi | 00 | MISSING | Non-existent file pointed to by a symbolic link (visible when you type ls -l) |
lc |
|
LEFTCODE, LEFT | Opening terminal code |
rc |
|
RIGHTCODE, RIGHT | Closing terminal code |
ec |
|
ENDCODE, END | Non-filename text |
*.extension | various |
|
Every file using this extension e.g. *.jpg |
rs | 0 |
|
|
mh | 00 | MULTIHARDLINK |
|
ca | 30;41 | CAPABILITY |
|
Colour & Effect options
Foreground | Background | Effects | |||
Code | Property | Code | Property | Code | Property |
30 | Black | 40 | Black | 00 | Default |
31 | Red | 41 | Red | 01 | Bold |
32 | Green | 42 | Green | 04 | Underlined |
33 | Orange | 43 | Orange | 05 | Flashing Text |
34 | Blue | 44 | Blue | 07 | Reversed |
35 | Purple | 45 | Purple | 08 | Concealed |
36 | Cyan | 46 | Cyan |
|
|
37 | Grey | 47 | Grey |
|
|
Extra Colours | |||||
90 | Dark Grey | 100 | Dark Grey |
|
|
91 | Light Red | 101 | Light Red |
|
|
92 | Light Green | 102 | Light Green |
|
|
93 | Yellow | 103 | Yellow |
|
|
94 | Light Blue | 104 | Light Blue |
|
|
95 | Light Purple | 105 | Light Purple |
|
|
96 | Turquoise | 106 | Turquoise |
|
|
97 | White | 107 | White |
|
|