What do the different colours in Ubuntu's ls
command mean? For example, when I type the ls
command in one of my folders, I get one of the files in light green, the other (which is a folder) in blue with green highlighting.
What do those colours mean, and there is any manual about all the colours?
For your information:
To turn the color off, you have to comment out the following lines in
.bashrc
.Also if you want to see your own bash color meanings,then copy/paste the following codes in your terminal.
Output:
Note:
man dir_colors
in terminal.You can find out what colours
ls
uses by looking at the$LS_COLORS
variable:In addition, files are colourised by attributes:
aac, au, flac, mid, midi, mka, mp3, mpc, ogg, ra, wav, axa, oga, spx, xspf.
tar, tgz, arj, taz, lzh, lzma, tlz, txz, zip, z, Z, dz, gz, lz, xz, bz2, bz, tbz, tbz2, tz, deb, rpm, jar, rar, ace, zoo, cpio, 7z, rz.
jpg, jpeg, gif, bmp, pbm, pgm, ppm, tga, xbm, xpm, tif, tiff, png, svg, svgz, mng, pcx, mov, mpg, mpeg, m2v, mkv, ogm, mp4, m4v, mp4v, vob, qt, nuv, wmv, asf, rm, rmvb, flc, avi, fli, flv, gl, dl, xcf, xwd, yuv, cgm, emf, axv, anx, ogv, ogx.
All this information is contained in the output of
dircolors --print-database
, but its formatting is rather unreadable.Here's a technical explanation of what's happening:
Example:
The colour code consists of three parts:
The first part before the semicolon represents the text style.
The second and third part are the colour and the background color:
Each part can be omitted, assuming starting on the left. i.e. "01" means bold, "01;31" means bold and red. And you would get your terminal to print in colour by escaping the instruction with
\33[
and ending it with anm
. 33, or 1B in hexadecimal, is the ASCII sign "ESCAPE" (a special character in the ASCII character set). Example:Prints "Hello World" in bright red.
The command
ls
with the argument--color=auto
(on Ubuntu,ls
is an alias forls --color=auto
) goes through all the file names and tries first to match different types, like Executable, Pipe and so on. It then tries to match regular expressions like *.wav and prints the resulting filename, enclosed in these colour-changing instructions for bash.[This expands on Karthick87's answer.]
Full list, with the default setup
ls -l
)Note that bold red looks orange, black looks dark grey, cyan looks blue/green, and bold magenta looks purple/pink/lavender.
Script to show colors
Output with default setup:
Output with my setup (custom dircolors and custom Solarized terminal theme):
I got the descriptions from
dircolors -p
andman dir_colors
, and filled in the gaps with my own research.The colors and descriptions are the same from at least 14.04 to 17.10.
If you type
dircolors
(echo $LS_COLORS
also works) from command line you will get a list of codes and colors for lots of filetypes in 1 line.dircolors --print-database
shows them 1 line at a time. Here is a short list (I tried to put in the most important ones). At the bottom there is an explanation about what the different codes at the end of each lines represents:00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
If you want to play around with this here is an example on how to set a color for a file:
This will set
*.ogg
and.mp3
tobold magenta
. And if you put it in your.bashrc
file it will become permanent.None of the answers here include the 256 color options in the latest versions of Ubuntu. I'm color deficient (some colors give me trouble near each other) so the default blue directory on black is real hard for me to read. What follows is my research to change that.
Type
dircolors -p |less
to see your current color code.The default .bashrc should already be configured not only to take advantage of the system color code, but also one in ~/.dircolors so dump the dircolors output to .dircolor so you can start with that using this command.
dircolors -p > ~/.dircolors
Alternative: pick up a very similar 256 color dircolors from seebi's solarized project.
Grab this colortest script and run it with the command
colortest -w
so you can see all the colors at once. Choose a color. I like the orange #208. I want that to be the text color so using this info on extended color codes, I can apply that.So you have a color, now what. First we have to create the string.
The first number will be an attribute code, most likely 00, but if you want it to blink go with 05:
Next pick append
;38;5;
to that attribute code to indicate your text color to get 00;38;5; and then append your color. I picked 208 so I get00;38;5;208
.If you want to also put a background on it, pick another color (let's say 56) with the colortest script and the append
;48;5;
for the background and 56 for the color to get a total string of00;38;5;208;48;5;56
.So now you have it, what do you do with it?
vim ~/.dircolors
and find the section you want to change (for me that is DIR) to the string we determined above "00;38;5;208".This won't apply immediately, you'll need to load the config. Use
dircolors ~/.dircolors
to the get code to set your LS_COLORS variable. You could just paste that into your terminal session or you can close your terminal and reopen it. You could also pipe that into a file and run it as a shell script.You can do this same procedure with 16 colors. You don't need the special ;38;5 or ;48;5 stuff. Just toss the numbers into the string and enjoy the simplicity.
Thanks to Dan and seebi for their notes and code on this.