How To Turn On/Off Colors For ls Command In Bash On a Linux/Unix

How do I turn on or off file name colors (ls command colors) in bash shell on a Linux or Unix like operating systems?

Most modern Linux distributions and Unix systems comes with alias that defines colors for your file. However, ls command is responsible for displaying color on screen for files, directories and other file system objects.

[donotprint][/donotprint]By default, color is not used to distinguish types of files. You need to pass --color option to the ls command on Linux. If you are using OS X or BSD based system pass -G option to the ls command. The syntax is as follows to turn on or off colors.

How to turn off colors for ls command

Type the following command
$ ls --color=none
Or just remove alias with the unalias command:
$ unalias ls
Please note that the following bash shell aliases are defined to display color with the ls command. Use combination of alias command and grep command as follows:
$ alias | grep ls
Sample outputs

alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'

How to turn on colors for ls command

Use any one of the following command:
$ ls --color=auto
$ ls --color=tty

Define bash shell aliases if you want:
alias ls='ls --color=auto'
You can add or remove ls command alias to the ~/.bash_profile or ~/.bashrc file. Edit file using a text editor such as vi command:
$ vi ~/.bashrc
Append the following code:

# my ls command aliases #
alias ls='ls --color=auto'

Save and close the file in Vi/Vim text editor.

A note about *BSD/macOS/Apple OS X ls command

Pass the -G option to ls command to enable colorized output on a {Free,Net,Open}BSD or macOS and Apple OS X Unix family of operating systems:
$ ls -G
Sample outputs:

How to enable colorized output for the ls command in Mac OS X Terminal

How do I skip colorful ls command output temporarily?

You can always disable bash shell aliases temporarily using any one of the following syntax:
command ls

This entry is 2 of 5 in the Coloring Outputs in the CLI Apps Tutorial series. Keep reading the rest of the series:

  1. How to enable colorized output for ls command in MacOS X Terminal
  2. How To Turn On/Off Colors For ls Command In Bash On a Linux/Unix
  3. Turn off color in Linux terminal/bash session
  4. Turn On or Off Color Syntax Highlighting In vi or vim Editor
  5. BASH Shell: Change The Color of My Shell Prompt Under Linux or UNIX

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Leave a Reply

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

Previous Post

How to Make Website WCAG Compliant?

Next Post

Link download Kali Linux 2020.1 (ISO + Torrent)

Related Posts