LSCOLORS Cheat-sheet

Home

1 LSCOLORS Overview

You can define color for each attribute with the help of LSCOLORS, when colors are enabled with CLICOLOR. This string is a concatenation of pairs of the format fb, where f is the foreground color and b is the background color. The default value is:

exfxcxdxbxegedabagacad Where,

ls Foreground Background
Attribute color color
directory e x
symbolic f x
socket c x
pipe d x
executable b x
block e g
character e d
executable a b
executable a g
directory a c
directory a d

The color and their code values are as follows:

Code Meaning (Color)

  • a Black
  • b Red
  • c Green
  • d Brown
  • e Blue
  • f Magenta
  • g Cyan
  • h Light grey
  • A Bold black, usually shows up as dark grey
  • B Bold red
  • C Bold green
  • D Bold brown, usually shows up as yellow
  • E Bold blue
  • F Bold magenta
  • G Bold cyan
  • H Bold light grey; looks like bright white
  • x Default foreground or background

You can now customize it as per your need in ~/.bashrc:

  • export CLICOLOR=1
  • export LSCOLORS=cd GxFxCxDxBxegedabagaced I think this is a typo

-—

2 Type of files recognized (for ls command)

When running a command that displays files in the shell, like the ls command, There are default colors set for each file type as follows:

2.1 Default File types for LSCOLORS

  1. directory
  2. symbolic link – special kind of file that contains a reference to another file or directory.
  3. socket – special kind of file used for inter-process communication.
  4. pipe – special file that connects the output of one process to the input of another.
  5. executable
  6. block special – a kind of device file.
  7. character special – a kind of device file.
  8. executable with setuid bit set (setuid is a short for set user ID upon execution).
  9. executable with setgid bit set (setgid is a short for set group ID upon execution).
  10. directory writable to others, with sticky bit – only the owner can rename or delete files.
  11. directory writable to others, without sticky bit – any user with write and execution permissions can rename or delete files.

And the different letters correspond to:

  • a black
  • b red
  • c green
  • d brown
  • e blue
  • f magenta
  • g cyan
  • h light grey
  • x default color

The same letters in uppercase indicate Bold.

  • B red
  • C green
  • D brown
  • E blue
  • F magenta
  • G cyan
  • H light grey
  • X default color

2.2 Terminal Defaults

The Terminal default colors, described by exfxcxdxbxegedabagacad, and ordered by file type / text color / background color, are:

  • ex –> directory / blue / default
  • fx –> symbolic link / magenta / default
  • cx –> socket / green / default
  • dx –> pipe / brown / default
  • bx –> executable / red / default
  • eg –> block special / blue / cyan
  • ed –> character special / blue / brown
  • ab –> executable with setuid / black / red
  • ag –> executable without setuid / black / cyan
  • ac –> directory with sticky / black / green
  • ad –> directory without sticky / black / brown

2.3 Altering the default colors for file types:

These file type colors can be altered by editing your LSCOLORS env. variable, Usually this is done in your .bashrc or .bashprofile for bash and in ~/.config/zsh/.zhrc file for zsh. On my AlmaLinux system the variable was LS_COLORS I suggest that you take a backup of your LSCOLORS variable before playing with it, so you can not be burned with some duffus mistake.

BACKUP_LS_COLORS=$LS_COLORS
echo $LS_COLORS
rs=0 di=38;5;33 ln=38;5;51 mh=00 pi=40;38;5;11 so=38;5;13 do=38;5;5
bd=48;5;232;38;5;11 cd=48;5;232;38;5;3 or=48;5;232;38;5;9 mi=01;05;37;41
su=48;5;196;38;5;15 sg=48;5;11;38;5;16 ca=48;5;196;38;5;226
tw=48;5;10;38;5;16 ow=48;5;10;38;5;21 st=48;5;21;38;5;15 ex=38;5;40
*.tar=38;5;9 *.tgz=38;5;9 *.arc=38;5;9 *.arj=38;5;9 *.taz=38;5;9
*.lha=38;5;9 *.lz4=38;5;9 *.lzh=38;5;9 *.lzma=38;5;9 *.tlz=38;5;9
*.txz=38;5;9 *.tzo=38;5;9 *.t7z=38;5;9 *.zip=38;5;9 *.z=38;5;9 *.dz=38;5;9
*.gz=38;5;9 *.lrz=38;5;9 *.lz=38;5;9 *.lzo=38;5;9 *.xz=38;5;9 *.zst=38;5;9
*.tzst=38;5;9 *.bz2=38;5;9 *.bz=38;5;9 *.tbz=38;5;9 *.tbz2=38;5;9
*.tz=38;5;9 *.deb=38;5;9 *.rpm=38;5;9 *.jar=38;5;9 *.war=38;5;9 *.ear=38;5;9
*.sar=38;5;9 *.rar=38;5;9 *.alz=38;5;9 *.ace=38;5;9 *.zoo=38;5;9 *.cpio=38;5;9
*.7z=38;5;9 *.rz=38;5;9 *.cab=38;5;9 *.wim=38;5;9 *.swm=38;5;9 *.dwm=38;5;9
*.esd=38;5;9 *.jpg=38;5;13 *.jpeg=38;5;13 *.mjpg=38;5;13 *.mjpeg=38;5;13
*.gif=38;5;13 *.bmp=38;5;13 *.pbm=38;5;13 *.pgm=38;5;13 *.ppm=38;5;13
*.tga=38;5;13 *.xbm=38;5;13 *.xpm=38;5;13 *.tif=38;5;13 *.tiff=38;5;13
*.png=38;5;13 *.svg=38;5;13 *.svgz=38;5;13 *.mng=38;5;13 *.pcx=38;5;13
*.mov=38;5;13 *.mpg=38;5;13 *.mpeg=38;5;13 *.m2v=38;5;13 *.mkv=38;5;13
*.webm=38;5;13 *.ogm=38;5;13 *.mp4=38;5;13 *.m4v=38;5;13 *.mp4v=38;5;13
*.vob=38;5;13 *.qt=38;5;13 *.nuv=38;5;13 *.wmv=38;5;13 *.asf=38;5;13
*.rm=38;5;13 *.rmvb=38;5;13 *.flc=38;5;13 *.avi=38;5;13 *.fli=38;5;13
*.flv=38;5;13 *.gl=38;5;13 *.dl=38;5;13 *.xcf=38;5;13 *.xwd=38;5;13
*.yuv=38;5;13 *.cgm=38;5;13 *.emf=38;5;13 *.ogv=38;5;13 *.ogx=38;5;13
*.aac=38;5;45 *.au=38;5;45 *.flac=38;5;45 *.m4a=38;5;45 *.mid=38;5;45
*.midi=38;5;45 *.mka=38;5;45 *.mp3=38;5;45 *.mpc=38;5;45 *.ogg=38;5;45
*.ra=38;5;45 *.wav=38;5;45 *.oga=38;5;45 *.opus=38;5;45 *.spx=38;5;45
*.xspf=38;5;45

The filetype specifies the filesystem object type as follows:

di directory
ex executable
fi regular file
ln symbolic link
bd block device
sg SGID special permission file
su SUID special permission file
*.ext file with extension .ext
For e xample, in my .bashrc file I can set:
LS_COLORS="di=34:ex=32:fi-1;37:*.jpg=32:*.png=32:*.zip=31:*.tar.gz=31:*.org=36"

Where the 36 is the ANSI color for cyan. Note that this does NOT work for my Macbook pro, but does on my linux system.

For example, on my Linux host I ran this:

$ echo "$LS_COLORS"
rs=0:di=38;5;33:ln=38;5;51:mh=00:pi=40;38;5;11:so=38;5;13:do=38;5;5:bd=48;5;232;38;5;11:cd=48;5;232;38;5;3:or=48;5;232;38;5;9:mi=01;05;37;41:su=48;5;196;38;5;15:sg=48;5;11;38;5;16:ca=48;5;196;38;5;226:tw=48;5;10;38;5;16:ow=48;5;10;38;5;21:st=48;5;21;38;5;15:ex=38;5;40:*.tar=38;5;9:*.tgz=38;5;9:*.arc=38;5;9:*.arj=38;5;9:*.taz=38;5;9:*.lha=38;5;9:*.lz4=38;5;9:*.lzh=38;5;9:*.lzma=38;5;9:*.tlz=38;5;9:*.txz=38;5;9:*.tzo=38;5;9:*.t7z=38;5;9:*.zip=38;5;9:*.z=38;5;9:*.dz=38;5;9:*.gz=38;5;9:*.lrz=38;5;9:*.lz=38;5;9:*.lzo=38;5;9:*.xz=38;5;9:*.zst=38;5;9:*.tzst=38;5;9:*.bz2=38;5;9:*.bz=38;5;9:*.tbz=38;5;9:*.tbz2=38;5;9:*.tz=38;5;9:*.deb=38;5;9:*.rpm=38;5;9:*.jar=38;5;9:*.war=38;5;9:*.ear=38;5;9:*.sar=38;5;9:*.rar=38;5;9:*.alz=38;5;9:*.ace=38;5;9:*.zoo=38;5;9:*.cpio=38;5;9:*.7z=38;5;9:*.rz=38;5;9:*.cab=38;5;9:*.wim=38;5;9:*.swm=38;5;9:*.dwm=38;5;9:*.esd=38;5;9:*.jpg=38;5;13:*.jpeg=38;5;13:*.mjpg=38;5;13:*.mjpeg=38;5;13:*.gif=38;5;13:*.bmp=38;5;13:*.pbm=38;5;13:*.pgm=38;5;13:*.ppm=38;5;13:*.tga=38;5;13:*.xbm=38;5;13:*.xpm=38;5;13:*.tif=38;5;13:*.tiff=38;5;13:*.png=38;5;13:*.svg=38;5;13:*.svgz=38;5;13:*.mng=38;5;13:*.pcx=38;5;13:*.mov=38;5;13:*.mpg=38;5;13:*.mpeg=38;5;13:*.m2v=38;5;13:*.mkv=38;5;13:*.webm=38;5;13:*.ogm=38;5;13:*.mp4=38;5;13:*.m4v=38;5;13:*.mp4v=38;5;13:*.vob=38;5;13:*.qt=38;5;13:*.nuv=38;5;13:*.wmv=38;5;13:*.asf=38;5;13:*.rm=38;5;13:*.rmvb=38;5;13:*.flc=38;5;13:*.avi=38;5;13:*.fli=38;5;13:*.flv=38;5;13:*.gl=38;5;13:*.dl=38;5;13:*.xcf=38;5;13:*.xwd=38;5;13:*.yuv=38;5;13:*.cgm=38;5;13:*.emf=38;5;13:*.ogv=38;5;13:*.ogx=38;5;13:*.aac=38;5;45:*.au=38;5;45:*.flac=38;5;45:*.m4a=38;5;45:*.mid=38;5;45:*.midi=38;5;45:*.mka=38;5;45:*.mp3=38;5;45:*.mpc=38;5;45:*.ogg=38;5;45:*.ra=38;5;45:*.wav=38;5;45:*.oga=38;5;45:*.opus=38;5;45:*.spx=38;5;45:*.xspf=38;5;45:

Those were all set as my system defaults. I can add a single filetype and it will NOT change all the defaults already set up. For instance:

LS_COLORS="*.org=1;33"

added the org file type but left all the defaults as they were. Although,… If I said echo $LS_COLORS I only got *org=1;33 and did not see the remaining list of color specs. They still were in effect though, when I would run an ls command…. hmmmm..??

I can still change the defaults as well by doing the following:

3 dircolors

On Linux systems, you can install some utilities package (can't remember which one) that includes a command dircolors That lets you manage coloration of files.

dircolors --print-database

This will display the current settings of all your file endings. You can edit this database as follows:

The output of the above command also explains what it does. Here are some experpts from that output:

Configuration file for dircolors, a utility to help you set the LSCOLORS environment variable used by GNU ls with the –color option. Copyright (C) 1996-2018 Free Software Foundation, Inc. Copying and distribution of this file, with or without modification, are permitted provided the copyright notice and this notice are preserved. The keywords COLOR, OPTIONS, and EIGHTBIT (honored by the slackware version of dircolors) are recognized but ignored. Below are TERM entries, which can be a glob patterns, to match against the TERM environment variable to determine if it is colorizable.

TERM Eterm
TERM ansi
TERM *color*
TERM con[0-9]*x[0-9]*
TERM cons25
TERM console
TERM cygwin
TERM dtterm
TERM gnome
TERM hurd
TERM jfbterm
TERM konsole
TERM kterm
TERM linux
TERM linux-c
TERM mlterm
TERM putty
TERM rxvt*
TERM screen*
TERM st
TERM terminator
TERM tmux*
TERM vt100
TERM xterm*

Below are the color init strings for the basic file types. A color init string consists of one or more of the following numeric codes:

  • Attribute codes:

~ 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed

  • Text color codes: 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
  • Background color codes: 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
  • #NORMAL 00 # no color code at all
  • #FILE 00 # regular file: use no color at all
  • RESET 0 # reset to "normal" color
          DIR 01;34 # directory
      LINK 01;36 # symbolic link. (If you set this to 'target' instead of a
     # numerical value, the color is as for the file pointed to.)
    MULTIHARDLINK 00 # regular file with more than one link
    FIFO 40;33 # pipe
    SOCK 01;35 # socket
    DOOR 01;35 # door
    BLK 40;33;01 # block device driver
    CHR 40;33;01 # character device driver
    ORPHAN 40;31;01 # symlink to nonexistent file, or non-stat'able file ...
    MISSING 00 # ... and the files they point to
    SETUID 37;41 # file that is setuid (u+s)
    SETGID 30;43 # file that is setgid (g+s)
    CAPABILITY 30;41 # file with capability
    STICKY_OTHER_WRITABLE 30;42 # dir that is sticky and other-writable (+t,o+w)
    OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky
    STICKY 37;44 # dir with the sticky bit set (+t) and not other-writable
    # This is for files with execute permission:
    EXEC 01;32
    # List any file extensions like '.gz' or '.tar' that you would like ls
    # to colorize below. Put the extension, a space, and the color init string.
    # (and any comments you want to add after a '#')
    # If you use DOS-style suffixes, you may want to uncomment the following:
    #.cmd 01;32 # executables (bright green)
    #.exe 01;32
    #.com 01;32
    #.btm 01;32
    #.bat 01;32
    # Or if you want to colorize scripts even if they do not have the
    # executable bit actually set.
    #.sh 01;32
    #.csh 01;32
     # archives or compressed (bright red)
    .tar 01;31
    .tgz 01;31
    .arc 01;31
    .arj 01;31
    .taz 01;31
    .lha 01;31
    .lz4 01;31
    .lzh 01;31
    .lzma 01;31
    .tlz 01;31
    .txz 01;31
    .tzo 01;31
    .t7z 01;31
    .zip 01;31
    .z 01;31
    .dz 01;31
    .gz 01;31
    .lrz 01;31
    .lz 01;31
    .lzo 01;31
    .xz 01;31
    .zst 01;31
    .tzst 01;31
    .bz2 01;31
    .bz 01;31
    .tbz 01;31
    .tbz2 01;31
    .tz 01;31
    .deb 01;31
    .rpm 01;31
    .jar 01;31
    .war 01;31
    .ear 01;31
    .sar 01;31
    .rar 01;31
    .alz 01;31
    .ace 01;31
    .zoo 01;31
    .cpio 01;31
    .7z 01;31
    .rz 01;31
    .cab 01;31
    .wim 01;31
    .swm 01;31
    .dwm 01;31
    .esd 01;31
    # image formats
    .jpg 01;35
    .jpeg 01;35
    .mjpg 01;35
    .mjpeg 01;35
    .gif 01;35
    .bmp 01;35
    .pbm 01;35
    .pgm 01;35
    .ppm 01;35
    .tga 01;35
    .xbm 01;35
    .xpm 01;35
    .tif 01;35
    .tiff 01;35
    .png 01;35
    .svg 01;35
    .svgz 01;35
    .mng 01;35
    .pcx 01;35
    .mov 01;35
    .mpg 01;35
    .mpeg 01;35
    .m2v 01;35
    .mkv 01;35
    .webm 01;35
    .ogm 01;35
    .mp4 01;35
    .m4v 01;35
    .mp4v 01;35
    .vob 01;35
    .qt 01;35
    .nuv 01;35
    .wmv 01;35
    .asf 01;35
    .rm 01;35
    .rmvb 01;35
    .flc 01;35
    .avi 01;35
    .fli 01;35
    .flv 01;35
    .gl 01;35
    .dl 01;35
    .xcf 01;35
    .xwd 01;35
    .yuv 01;35
    .cgm 01;35
    .emf 01;35
    # https://wiki.xiph.org/MIME_Types_and_File_Extensions
    .ogv 01;35
    .ogx 01;35
    # audio formats
    .aac 00;36
    .au 00;36
    .flac 00;36
    .m4a 00;36
    .mid 00;36
    .midi 00;36
    .mka 00;36
    .mp3 00;36
    .mpc 00;36
    .ogg 00;36
    .ra 00;36
    .wav 00;36
    # https://wiki.xiph.org/MIME_Types_and_File_Extensions
    .oga 00;36
    .opus 00;36
    .spx 00;36
    .xspf 00;36
    

$/home/zintis #+ENDEXAMPLE

4 asdf

5 Focus Follows Mouse tip for Mac OSX

  • defaults write com.apple.Terminal FocusFollowsMouse -string YES

from the command prompt. Only has to be done once.

- defaults write com.apple.Terminal FocusFollowsMouse -string NO to revert back to original.

5.1 Trying this for emacs too.

  • defaults write org.gnu.Emacs FocusFollowsMouse -string YES

6 Colours for the Bash prompt:

You must include the entire color code information between the \[ and \] characters. Inside the tag, you must begin with either \033[ or \e[ to indicate to Bash that this is color information.

Both \033[ and \e[ do the same thing. \e[ is shorter so might be more convenient to use, but we’ll use \033[ here as it matches what’s used by default.

You must indicate the end of a colour tag with m\

So, every color tag will look like: \[\033[COLORm\] where foreground COLOR is:

  • Black: 30
  • Red: 31
  • Green: 32
  • Yellow: 33
  • Blue: 34
  • Purple: 35
  • Cyan: 36
  • White: 37

Bash also allows you to change the color of foreground text, add attributes like “bold” or “underline” to the text, and set a background color.

Attributes are added before the color number So, every attribute color tag will look like \[\033[ATTRIBUTE;COLORm\] or also, \e in place of \033

Where ATTRIBUTE is:

  • 0 Normal text ( the default )
  • 1 Bold or light text
  • 2 Dim text
  • 3
  • 4 Underlined text
  • 5 Blinking text
  • 7 Reversed text
  • 8 Hidden text.

Background colours cannot have attributes, but are:

  • 40 Black
  • 41 Red
  • 42 Green
  • 43 Yellow
  • 44 Blue
  • 45 Purple
  • 46 Cyan
  • 47\ White

So just changing the background colour to purple would be: \[\033[45m\]

You can specify both foreground and background color tags. For example, 42 represents a green background and 31 represents red text. So, to make the default prompt become red text on a green background, you’d use both the color prompts, one after another, OR, separated by a semicolon.

  • PS1="\[\033[42m\]\[\033[31m\]\u@\h:\w\$ "
  • PS1="\[\033[42m\]\[\033[01;31m\]\u@\h:\w\$ "

The background and foreground text colors keep going past the prompt unless you specify color code 00 clear the color information.

You can also use this tag within the variable to reset formatting back to default somewhere in your prompt. For example, the following line would end all coloring before the \$ character.

  • PS1="\[\033[42m\]\[\033[31m\]\u@\h:\w\\[\033[00m\]\$ "

Some examples:

echo -e "\e[31;44mred on blue\e[0m"
echo -e "\e[34;41mblue on red\e[0m"

7 tput command

You can also change color of the PS1 prompt using tput. This works nicely when changing colour in a bash script output. /

NC=`tput setaf 0`
RED=`tput setaf 1`
GREEN=`tput setaf 2`
YELLOW=`tput setaf 3`
BLUE=`tput setaf 4`
PURPLE=`tput setaf 5`
CYAN=`tput setaf 6`
tput bold

echo "${RED}  tput setaf 1"
echo "${GREEN}  tput setaf 2"
echo "${YELLOW}  tput setaf 3"
echo "${BLUE}  tput setaf 4"
echo "${PURPLE}  tput setaf 5"
echo "${CYAN}  tput setaf 6"

This looks like this on my Macbook:

tput.png

Figure 1: tput script output

And if you :

  • export PS1="\[$(tput bold)$(tput setb 4)$(tput setaf 7)\]\u@\h:\w $ \[$(tput sgr0)\]“
tput Color Capabilities:
tput setab [1-7] – Set a background color using ANSI escape
tput setb [1-7] – Set a background color
tput setaf [1-7] – Set a foreground color using ANSI escape
tput setf [1-7] – Set a foreground color
tput Text Mode Capabilities:
tput bold – Set bold mode
tput dim – turn on half-bright mode
tput smul – begin underline mode
tput rmul – exit underline mode
tput rev – Turn on reverse mode
tput smso – Enter standout mode (bold on rxvt)
tput rmso – Exit standout mode
tput sgr0 – Turn off all attributes
Color Code for tput:
0 – Black
1 – Red
2 – Green
3 – Yellow
4 – Blue
5 – Magenta
6 – Cyan
7 – White   

7.1 Home