Colorize bash

(1) In your $HOME directory, create ..dir_colors file:

  1. # Below, there should be one TERM entry for each termtype that is colorizable
  2. TERM ansi
  3. TERM color-xterm
  4. TERM con132x25
  5. TERM con132x30
  6. TERM con132x43
  7. TERM con132x60
  8. TERM con80x25
  9. TERM con80x28
  10. TERM con80x30
  11. TERM con80x43
  12. TERM con80x50
  13. TERM con80x60
  14. TERM cons25
  15. TERM console
  16. TERM cygwin
  17. TERM dtterm
  18. TERM Eterm
  19. TERM gnome
  20. TERM konsole
  21. TERM kterm
  22. TERM linux
  23. TERM linux-c
  24. TERM mach-color
  25. TERM putty
  26. TERM rxvt
  27. TERM rxvt-cygwin
  28. TERM rxvt-cygwin-native
  29. TERM rxvt-unicode
  30. TERM screen
  31. TERM screen-bce
  32. TERM screen-w
  33. TERM screen.linux
  34. TERM vt100
  35. TERM xterm
  36. TERM xterm-256color
  37. TERM xterm-color
  38. TERM xterm-debian
  39. # Below are the color init strings for the basic file types. A color init
  40. # string consists of one or more of the following numeric codes:
  41. # Attribute codes:
  42. # 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
  43. # Text color codes:
  44. # 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
  45. # Background color codes:
  46. # 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
  47. NORMAL 00 # global default, although everything should be something.
  48. FILE 00 # normal file
  49. DIR 01;34 # directory
  50. LINK 01;36 # symbolic link. (If you set this to 'target' instead of a
  51. # numerical value, the color will match the file pointed to)
  52. FIFO 40;33 # pipe
  53. SOCK 01;35 # socket
  54. DOOR 01;35 # door
  55. BLK 40;33;01 # block device driver
  56. CHR 40;33;01 # character device driver
  57. ORPHAN 01;05;37;41 # orphaned syminks
  58. MISSING 01;05;37;41 # ... and the files they point to
  59. # This is for files with execute permission:
  60. EXEC 01;32
  61. # List any file extensions like '.gz' or '.tar' that you would like ls
  62. # to colorize below. Put the extension, a space, and the color init string.
  63. # (and any comments you want to add after a '#')
  64. .cmd 01;32 # executables (bright green)
  65. .exe 01;32
  66. .com 01;32
  67. .btm 01;32
  68. .bat 01;32
  69. .sh 01;32
  70. .csh 01;32
  71. .tar 01;31 # archives / compressed (bright red)
  72. .tgz 01;31
  73. .arj 01;31
  74. .taz 01;31
  75. .lzh 01;31
  76. .zip 01;31
  77. .z 01;31
  78. .Z 01;31
  79. .gz 01;31
  80. .bz2 01;31
  81. .bz 01;31
  82. .tbz2 01;31
  83. .tz 01;31
  84. .deb 01;31
  85. .rpm 01;31
  86. .rar 01;31 # app-arch/rar
  87. .ace 01;31 # app-arch/unace
  88. .zoo 01;31 # app-arch/zoo
  89. .cpio 01;31 # app-arch/cpio
  90. .7z 01;31 # app-arch/p7zip
  91. .rz 01;31 # app-arch/rzip
  92. .jpg 01;35 # image formats
  93. .jpeg 01;35
  94. .gif 01;35
  95. .bmp 01;35
  96. .ppm 01;35
  97. .tga 01;35
  98. .xbm 01;35
  99. .xpm 01;35
  100. .tif 01;35
  101. .tiff 01;35
  102. .png 01;35
  103. .mng 01;35
  104. .xcf 01;35
  105. .pcx 01;35
  106. .mpg 01;35
  107. .mpeg 01;35
  108. .m2v 01;35 # MPEG-2 Video only
  109. .avi 01;35
  110. .mkv 01;35 # Matroska (http://matroska.org/)
  111. .ogm 01;35 # Ogg Media File
  112. .mp4 01;35 # "Offical" container for MPEG-4
  113. .m4v 01;35 # MPEG-4 Video only
  114. .mp4v 01;35 # MPEG-4 Video only
  115. .mov 01;35 # Quicktime (http://developer.apple.com/qa/qtw/qtw99.html)
  116. .qt 01;35 # Quicktime (http://developer.apple.com/qa/qtw/qtw99.html)
  117. .wmv 01;35 # Windows Media Video
  118. .asf 01;35 # Advanced Systems Format (contains Windows Media Video)
  119. .rm 01;35 # Real Media
  120. .rmvb 01;35 # Real Media Variable Bitrate
  121. .flc 01;35 # AutoDesk Animator
  122. .fli 01;35 # AutoDesk Animator
  123. .gl 01;35
  124. .dl 01;35
  125. .pdf 00;32 # Document files
  126. .ps 00;32
  127. .txt 00;32
  128. .patch 00;32
  129. .diff 00;32
  130. .log 00;32
  131. .tex 00;32
  132. .doc 00;32
  133. .mp3 00;36 # Audio files
  134. .wav 00;36
  135. .mid 00;36
  136. .midi 00;36
  137. .au 00;36
  138. .ogg 00;36
  139. .flac 00;36
  140. .aac 00;36

(2) Add following statements in /etc/profile:

  1. eval $(dircolors -b ~/.dir_colors)
  2. if [[ ${EUID} == 0 ]] ; then
  3. PS1='\[\033[01;31m\]\h\[\033[01;34m\] \W \$\[\033[00m\] '
  4. else
  5. PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] '
  6. fi
  7. CLICOLOR="YES"; export CLICOLOR
  8. LSCOLORS="ExGxFxdxCxDxDxhbadExEx"; export LSCOLORS

Reference:
Colorize your bash like linux..