To customize the colors used by the ls command, you can set the LS_COLORS environment variable in your shell configuration file (like .bashrc or .bash_profile). This variable defines the color codes for different file types and attributes.
Steps to Customize ls Colors:
-
Open your shell configuration file:
You can use a text editor to open your.bashrcor.bash_profilefile. For example:nano ~/.bashrc -
Set the
LS_COLORSvariable:
You can define the colors for different file types. Here’s an example of how to set it:export LS_COLORS='di=34:fi=0:ln=36:pi=33:so=35:bd=46;34:cd=46;34:or=31;43:mi=05;37;41'In this example:
diis for directories (blue).fiis for regular files (default).lnis for symbolic links (cyan).piis for pipes (yellow).sois for sockets (magenta).bdandcdare for block and character devices (light blue background).oris for orphaned files (red text on yellow background).miis for missing files (white text on red background).
-
Apply the changes:
After editing the file, save it and then run:source ~/.bashrcThis command will apply the changes without needing to restart the terminal.
-
Test the colors:
Now, when you runls --color, you should see the customized colors based on yourLS_COLORSsettings.
Note:
You can find more color codes and customize them according to your preferences. The format for defining colors is:
type=color_code
Where type can be di, fi, ln, etc., and color_code can be a combination of foreground and background colors.
