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

See all Bash/Shell scripting related FAQ
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. 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.
Tutorial details
Difficulty level Easy
Root privileges No
Requirements Linux or Unix terminal
Category User
OS compatibility AIX AlmaLinux Alpine Amazon Linux Arch CentOS Debian Fedora FreeBSD HP-UX Linux macOS Mint Mint NetBSD OpenBSD openSUSE Pop!_OS RHEL Rocky Slackware Stream SUSE Ubuntu Unix WSL
Est. reading time 2 minutes

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 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:
$ \ls
$ /bin/ls
$ command ls
$ '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

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

1 comment… add one
  • Philippe Petrinko Apr 2, 2010 @ 8:24

    Well may be the title would be better if it would mention [ ls ].
    something like:
    How to turn on or off colors _for ls command_ in bash

Leave a Reply

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

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.