Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report