Mac displays different types of files in different colors in Terminal (Terminal)

Source: Internet
Author: User
Tags bit set


For those who switch from Unix/Linux to Mac, "terminal" is a frequently used tool. However, many people may have discovered that when we use the ls command to display the directory content, "terminal" does not use color to display special types of files, such as directories and executable files. It is inconvenient to display the color only when "ls-G" is used. Is there a way to display the color by default? Of course, there are methods. Solution 1 the first solution is to automatically convert ls to ls-G. In the user directory (~) Create a file named. bash_profile. If the file already exists, edit the file directly. In ~ /. Add the following content to bash_profile: alias ls = "ls-G" to save the file and restart the terminal ". Then, run the ls command, and we can see that the file can be displayed in color. Www.2cto.com solution 2 Although the above solution solves the color display problem, but there is still a deficiency, that is, the display color cannot be set. \ For example, if I want to display the directory in red, this method cannot be done. Let's take a look at a better solution. It is also modified ~ /. Bash_profile file, add the following two lines of configuration to the file. Export CLICOLOR = 1 export LSCOLORS = gxfxaxdxcxegedabagacad save the file and run "terminal" again. We found that the directory color changed from blue to blue. How should I set the configuration to my favorite color? The following describes some of these configurations. ~ /. Bash_profile is the configuration file of the current logon user in bash shell. Bash is the default shell in "terminal. Alias ls = "ls-G" is an alias for "ls-G". When ls is executed, it is equivalent to executing ls-G. CLICOLOR is used to set whether to display the color. CLI is the abbreviation of Command Line Interface. LSCOLORS is used to set the color of various file types when CLICOLOR is enabled. Each two letters in LSCOLORS is a group. The text color and background color of a file type are set. LSCOLORS contains 11 sets of colors. The following file types are set in sequence: alibaba directory symbolic link socket pipe executable block special character special executable with setuid bit set executable with setgid bit set directory writable to others, with sticky bit directory writable to others, without sticky bit LSCOLORS, the color of the letter is as follows: a black B red c green d brown e blue f Foreign Red g blue h light gray A black bold B red bold C green bold D brown bold E blue bold F Foreign red bold G blue bold H light gray bold x is the default color, if you want to display the directory in red, you can set LSCOLORS to bxfxaxdxcxegedabagacad.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.