How to customize ls colors?

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:

  1. Open your shell configuration file:
    You can use a text editor to open your .bashrc or .bash_profile file. For example:

    nano ~/.bashrc
  2. Set the LS_COLORS variable:
    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:

    • di is for directories (blue).
    • fi is for regular files (default).
    • ln is for symbolic links (cyan).
    • pi is for pipes (yellow).
    • so is for sockets (magenta).
    • bd and cd are for block and character devices (light blue background).
    • or is for orphaned files (red text on yellow background).
    • mi is for missing files (white text on red background).
  3. Apply the changes:
    After editing the file, save it and then run:

    source ~/.bashrc

    This command will apply the changes without needing to restart the terminal.

  4. Test the colors:
    Now, when you run ls --color, you should see the customized colors based on your LS_COLORS settings.

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.

0 Comments

no data
Be the first to share your comment!