This has been tested and works on MacOS, RHEL/Fedora/Debian/Ubuntu/Alpine Linux, and all other flavors suporting xterm with 256 colors. The LS_COLORS
environment variable is widely interpreted by most *NIX operating systems and is how directory color is passed to the user's command line terminal. See the following UNIX man pages man dircolors
and man dir_colors
for more information.
-
Use
gls
from GNU coreutils. And a couple handy aliases to consider:-
gls -alhF --group-directories-first --color=auto
-
gls -alhtrF --group-directories-first --color=auto
-
-
gdircolors
-
gdircolors --print-database
-
gdircolors --print-ls-colors
Source the ls_colors.sh
into your environment in the following ways:
- For your user, put in your shell profile.
In this example, for MacOS or Linux, where you use bash shell as your terminal:
bash shell:
echo 'source $HOME/ls_colors/ls_colors.sh' >> $HOME/.bashrc
And then reload (ie: source ~/.bashrc
) or re-login.
- For system-wide on RHEL Linux
Place the ls_colors.sh
in your /etc/profile.d
folder:
sudo cp $HOME/ls_colors/ls_colors.sh /etc/profile.d
In the interest of customization, I've included ls_colors_print.rb
. This snippet will print out each of the colors per file type, and should make it easy to test and play around. Feel free to branch/fork and contribute to the project. Thank you!