Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to turn on or off the color display of ls commands in Linux/Unix Bash

Shulou Source: shulou.com Published: 2022-06-01 05:56:21 10月03日 Update

This article mainly introduces how to turn on or off the color display of ls command in Linux/Unix Bash. The article is very detailed and has certain reference value. Interested friends must finish reading it!

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

Most modern Linux distributions and Unix systems have an alias that defines the color of the file name. The ls command is then responsible for displaying the colors of files, directories, and other file system objects on the screen.

By default, file types are not distinguished by color. You need to pass the-- color option to the ls command on Linux. If you are using an OS X or BSD-based system, pass the-G option to the ls command. The syntax for turning colors on or off is as follows.

How to turn off the color of the ls command

Enter the following command:

$ls-color=none

Or use the unalias command to delete the alias:

$unalias ls

Notice that the following bash shell alias is defined to display colors with the ls command. This combination uses the alias command and the grep command:

$alias | grep ls

Sample output:

Alias l='ls-CF'alias la='ls-A'alias ll='ls-alF'alias ls='ls-- how color=auto' opens the color of the ls command

Use any of the following commands:

$ls-color=auto$ ls-color=tty

If you want, you can define the bash shell alias:

Alias ls='ls-color=auto'

You can add or remove ls aliases from ~ / .bash_profile or ~ / .bashrc files. Use a text editor such as vi to edit the file:

$vi ~ / .bashrc

Append the following code:

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

Just save and close the file in the Vi/Vim text editor.

Notes on the ls command in * BSD/macOS/Apple OS X

Pass the-G option to the ls command to enable color output on {Free, Net, Open} BSD or macOS and Apple OS X Unix operating system families:

$ls-G

Sample output:

How to enable color output for ls commands in a Mac OS X terminal

How to skip the ls command color output temporarily?

You can temporarily disable the bash shell alias using any of the following syntax:

\ ls/bin/lscommand ls'ls' above is all the contents of the article "how to turn on or off the color display of ls commands in Linux/Unix Bash". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Command color file alias system output color operating system content name text example article editor grammar facet admiral code value interest Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Apple vpn Shulou Technology Redmi