What do the different colors mean in ls?

  • Blue: Directory
  • Green: Executable or recognized data file
  • Cyan (Sky Blue): Symbolic link file
  • Yellow with black background: Device
  • Magenta (Pink): Graphic image file
  • Red: Archive file
  • Red with black background: Broken link

For your information:

  • To turn the color off, you have to comment out the following lines in .bashrc.

    # enable color support of ls and also add handy aliases
    #if [ -x /usr/bin/dircolors ]; then
    #    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    #    alias ls='ls --color=auto'
    #    #alias dir='dir --color=auto'
    #    #alias vdir='vdir --color=auto'
    #
    #    alias grep='grep --color=auto'
    #    alias fgrep='fgrep --color=auto'
    #    alias egrep='egrep --color=auto'
    #fi
    
  • Also if you want to see your own bash color meanings,then copy/paste the following codes in your terminal.

    eval $(echo "no:global default;fi:normal file;di:directory;ln:symbolic link;pi:named pipe;so:socket;do:door;bd:block device;cd:character device;or:orphan symlink;mi:missing file;su:set uid;sg:set gid;tw:sticky other writable;ow:other writable;st:sticky;ex:executable;"|sed -e 's/:/="/g; s/\;/"\n/g')           
    {      
      IFS=:     
      for i in $LS_COLORS     
      do        
        echo -e "\e[${i#*=}m$( x=${i%=*}; [ "${!x}" ] && echo "${!x}" || echo "$x" )\e[m" 
      done       
    } 
    

Output:
terminal output

Note:

  • For more information, type man dir_colors in terminal.

You can find out what colours ls uses by looking at the $LS_COLORS variable:

  • Turquoise: audio files1
  • Bright Red: Archives and compressed files2
  • Purple: images and videos3

In addition, files are colourised by attributes:

alt text


  1. aac, au, flac, mid, midi, mka, mp3, mpc, ogg, ra, wav, axa, oga, spx, xspf.

  2. 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.

  3. 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:

CHR 40;33;01

The colour code consists of three parts:

  • The first part before the semicolon represents the text style.

    • 00=none, 01=bold, 04=underscore, 05=blink, 07=reverse, 08=concealed.
  • The second and third part are the colour and the background color:

    • 30=black, 31=red, 32=green, 33=yellow, 34=blue, 35=magenta, 36=cyan, 37=white.

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 an m. 33, or 1B in hexadecimal, is the ASCII sign "ESCAPE" (a special character in the ASCII character set). Example:

"\33[1;31mHello World\33[m"

Prints "Hello World" in bright red.

The command ls with the argument --color=auto (on Ubuntu, ls is an alias for ls --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

  • Uncolored (white): file or non-filename text (e.g. permissions in the output of ls -l) or multi-hardlink file
  • Bold blue: directory
  • Bold cyan: symbolic link
  • Bold green: executable file
  • Bold red: archive file
  • Bold magenta: image file, video, graphic, etc. or door or socket
  • Cyan: audio file
  • Yellow with black background: pipe (AKA FIFO)
  • Bold yellow with black background: block device or character device
  • Bold red with black background: orphan symlink or missing file
  • Uncolored with red background: set-user-ID file
  • Black with yellow background: set-group-ID file
  • Black with red background: file with capability
  • White with blue background: sticky directory
  • Blue with green background: other-writable directory
  • Black with green background: sticky and other-writable directory

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

#!/bin/bash
# For LS_COLORS, print type and description in the relevant color.

declare -A descriptions=(
    [bd]="block device"
    [ca]="file with capability"
    [cd]="character device"
    [di]="directory"
    [do]="door"
    [ex]="executable file"
    [fi]="regular file"
    [ln]="symbolic link"
    [mh]="multi-hardlink"
    [mi]="missing file"
    [no]="normal non-filename text"
    [or]="orphan symlink"
    [ow]="other-writable directory"
    [pi]="named pipe, AKA FIFO"
    [rs]="reset to no color"
    [sg]="set-group-ID"
    [so]="socket"
    [st]="sticky directory"
    [su]="set-user-ID"
    [tw]="sticky and other-writable directory"
)

IFS=:
for ls_color in $LS_COLORS; do
    color="${ls_color#*=}"
    type="${ls_color%=*}"

    # Add description for named types.
    desc="${descriptions[$type]}"

    # Separate each color with a newline.
    if [[ $color_prev ]] && [[ $color != "$color_prev" ]]; then
        echo
    fi

    printf "\e[%sm%s%s\e[m " "$color" "$type" "${desc:+ ($desc)}"

    # For next loop
    color_prev="$color"
done
echo

Output with default setup:

gnome-terminal screenshot - default

Output with my setup (custom dircolors and custom Solarized terminal theme):

gnome-terminal screenshot - custom

I got the descriptions from dircolors -p and man dir_colors, and filled in the gaps with my own research.

The colors and descriptions are the same from 14.04 to 17.10.