[#]: subject: "Colors in ls Command Output: What do They Mean?" [#]: via: "https://itsfoss.com/ls-color-output/" [#]: author: "Sagar Sharma https://itsfoss.com/author/sagar/" [#]: collector: "lkxed" [#]: translator: "geekpi" [#]: reviewer: " " [#]: publisher: " " [#]: url: " " Colors in ls Command Output: What do They Mean? ====== I'm sure you must have used the ls command to [list the contents of a directory][1]. In Ubuntu and many other distributions, you'll see the ls command output in different colors. If you don't see it, you can get colored output like this: ``` ls --color=auto ``` But have you ever wondered what those colors mean in the ls command output? I'll answer the questions in this article. **I'll also show how to get colored output with ls command** if your terminal does not show it by default. ### Meaning of colors used in the ls command in Ubuntu > 🚧 There is no set standard for the colors in the ls command output. Different terminals and distributions use different color coding and you can also modify it to your liking. In other words, don't rely on the colors. **I am using the default Ubuntu terminal and its color profile in this section.** When you [list files using the ls command][2], it will use different colors to indicate different kinds of files. Most terminals will show the executable files, links, regular files and directories in different colors so that you can easily distinguish between them. Some terminals, like the default one in Ubuntu, take it to the next level and add more colors for music files, images and videos. For the demonstrations, I've listed files from different directories which filled my terminal window with different colors in Ubuntu: ![different colors used by the ls command][3] Looks confusing? Let me decode each one for you! | Color | Description | | :- | :- | | **Bold Blue** | Directories. | | **Uncolored** | File or multi-hard link. | | **Bold Cyan** | A symbolic link pointing to a file. | | **Bold Green** | An executable file (scripts with having an `.sh` extension). | | **Bold Red** | Archive file (mostly a tarball or zip file). | | **Magenta** | Indicates images and video files. | | **Cyan** | Audio files. | | **Yellow with black bg** | A pipe file (known as FIFO). | | **Blod red with black bg** | A broken symbolic link. | | **Uncolored (white) with red bg** | Indicates set-user-ID file. | | **Black with yellow bg** | Indicates set-group-ID file. | | **White with blue bg** | Shows a sticky directory. | | **Blue with green bg** | Points to Other-writable directory | | **Black with green bg** | When a directory has characteristics of both sticky and other-writable directories. | > 📋 Again, the above color data is based on the default settings of the terminal and if you change the color pallet, you won't get similar results. But what if your terminal doesn't show any colors? Well, there's a reason and solution for that. ### What if the ls command does not show colored output? Here's the thing. The ls command is not supposed to display colors in output by default. It will show the colors if you use the `--color=auto` flag. ``` ls --color=auto ``` Then why does the ls command add colors by default in Ubuntu and some other distributions? That's because your distribution has an alias set for the ls command to use the `--color=auto` flag when you execute the ls command: ``` alias ``` ![][4] So if the ls command is not showing the colorful output, the alias is not set by default. Now, you may use `--color=auto` flag whenever you use the ls command ![Use --color=auto flag with the ls command to get the colored output][5] But that's not very convenient. Instead, you should create alias and add it to your bashrc so that ls command displays colors by default. #### Create a permanent alias for ls to display colors To create a permanent alias, first, open the `.bashrc` file using the following command: ``` nano ~/.bashrc ``` [Go to the end of the file][6] using `Alt + /` and [paste the following line in the terminal][7]: ``` alias ls='ls --color=auto' ``` Once done, [save changes and exit from the nano][8] text editor. To take effect from the changes you've just made, source the `.bashrc` file: ``` source ~/.bashrc ``` That's it! From now on, you can use the colored output. ### Where does the ls command gets the color from? Now comes the interesting part. Where are the colors for the ls command defined? The answer is LS_COLORS. Yes. That's the special environment variable called LS_COLORS that defines the colors used by the ls command. ![Value of the LS_COLORS env variable in Ubuntu][9] That's good but who defines this variable? What if you wanted to make some changes? I'll answer these questions as well. Actually, you have a dedicated `dircolors` command to setup color for the ls command. Different shells have different formats for the color profile. This is why you should indicate the shell when you use this command. ![dircolors command output for bash][10] As you can see, it defines the LS_COLORS environment variable and exports it so that the variable is available for the subshell. Now, if you want to use it, you can either copy-paste it to your bashrc file or redirect the output like this: ``` dircolors -b >> .bashrc ``` And source the file so that the effects are immediately visible. You have to do it only once. #### Understanding the color profile The LS_COLORS has data in key-value pair separated by a colon (:). If the value has more than one part, they are separated by a semicolon (;). The key is usually predefined. The value part represents the colors. So, if it says `ln=01;36`, it means for symbolic links, the font is bold and the color (36) is cyan. 0 is for normal, 1 is for bold, 4 is for underlined. 31 is for red, 32 is for green etc. The color codes follow the [ANSI escape code][11]. Another example. `or=40;31;01` means that link to a non-existent file (key is or) uses black background (color code 40), red color and bold font (code 01). I think the order doesn't matter because the codes don't overlap. 31 is the code for the foreground red color and 41 is the color for the background red color. So if 41 is used, you know it is for the background color. ### Do more with the ls command The ls command can do a lot more and for that purpose, we made a detailed tutorial on how to use the ls command: **This [**tutorial was requested**][12] by an It's FOSS member in our community forum. If you have suggestions or tutorial requests, please [**use our Community platform**][13].** _With inputs from Abhishek Prakash._ -------------------------------------------------------------------------------- via: https://itsfoss.com/ls-color-output/ 作者:[Sagar Sharma][a] 选题:[lkxed][b] 译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 [a]: https://itsfoss.com/author/sagar/ [b]: https://github.com/lkxed/ [1]: https://itsfoss.com/list-directory-content/ [2]: https://itsfoss.com/ls-command/ [3]: https://itsfoss.com/content/images/2023/07/meaning-of-different-colors-shown-when-ls-command-is-used-2.png [4]: https://itsfoss.com/content/images/2023/07/reason-behind-ls-uses-colors-by-default-3.png [5]: https://itsfoss.com/content/images/2023/07/Use----color-auto-flag-with-the-ls-command-to-get-the-colored-output.png [6]: https://linuxhandbook.com/beginning-end-file-nano/ [7]: https://itsfoss.com/copy-paste-linux-terminal/ [8]: https://linuxhandbook.com/nano-save-exit/ [9]: https://itsfoss.com/content/images/2023/07/ls_colors-env-variable.png [10]: https://itsfoss.com/content/images/2023/07/dircolors-command-output.png [11]: https://en.wikipedia.org/wiki/ANSI_escape_code [12]: https://itsfoss.community/t/what-is-the-color-code-for-line-in-the-ubuntu-terminal/10791/18 [13]: https://itsfoss.community/c/topic-ideas/25