Definition of different colours for ‘ls’ command in Ubuntu 18.04 terminal

If you have used ls command in a terminal, you might have noticed that a variety of colours appear in the terminal. The below image would tell the meaning of each colour:

Here is a script that can be run on terminal and generates the above image:


#!/bin/bash
# For LS_COLORS, print type and description in the relevant colour:
IFS=:
for ls_color in $LS_COLORS; do
color="${ls_color#*=}"
type="${ls_color%=*}"
# Add descriptions for named types.
case "$type" in
bd) type+=" (block device)" ;;
ca) type+=" (file with capability)" ;;
cd) type+=" (character device)" ;;
di) type+=" (directory)" ;;
do) type+=" (door)" ;;
ex) type+=" (executable file)" ;;
fi) type+=" (regular file)" ;;
ln) type+=" (symbolic link)" ;;
mh) type+=" (multi-hardlink)" ;;
mi) type+=" (missing file)" ;;
no) type+=" (normal non-filename text)" ;;
or) type+=" (orphan symlink)" ;;
ow) type+=" (other-writable directory)" ;;
pi) type+=" (named pipe, AKA FIFO)" ;;
rs) type+=" (reset to no color)" ;;
sg) type+=" (set-group-ID)" ;;
so) type+=" (socket)" ;;
st) type+=" (sticky directory)" ;;
su) type+=" (set-user-ID)" ;;
tw) type+=" (sticky and other-writable directory)" ;;
esac
# Separate each color with a newline.
if [[ $color_prev ]] && [[ $color != $color_prev ]]; then
echo
fi
printf "\e[%sm%s\e[m " "$color" "$type"
# For next loop
color_prev="$color"
done
echo

Reference:
https://askubuntu.com/questions/17299/what-do-the-different-colors-mean-in-ls

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.