Display directories in bold - how to enable? with .bash_profile?

I am using a Linux server that displays directories in bold and files in regular font.


eg. $ ls produces

afile.txt afolder anotherfile.txt another folder


I would like to use this feature on some other servers. How can I do that? with .bash_profile?

If anyone has other ideas on how to distinguish folders from a file, would it be useful for them to know?

+4
source share
4 answers

You need to specify ls parameter --colors=… (for example, through an alias). To actually set up the LS_COLORS environment LS_COLORS used to define colors, one of the good ways is to create a configuration file for dircolors , for example. with only bold (attribute 1) directories:

 echo DIR 1 >~/.dir_colors 

Then, in your .bash_profile or .bashrc , eval dircolors output is executed in this file to set LS_COLORS according to your configuration. The corresponding lines in my .bashrc (copied from somewhere) look like this:

  if [ -n "$COLORTERM" ]; then alias ls='ls -F --color=auto' if [ -x "`which dircolors`" -a -r "$HOME/.dir_colors" ]; then eval `dircolors -b "$HOME/.dir_colors"` fi else alias ls='ls -F' fi 

Note that some terminals do not display the bold attribute as true in bold by default, but simply use a brighter color. You need to configure your terminal to become bold.

See dircolors --print-database for an example of a "complete" configuration file.

+6
source

It is executed with an environment variable. Start by reading the ls man page:

  $ man ls 

You may not be able to get only bold, but only bold with a certain color.

+1
source

If anyone has other ideas on how to distinguish folders from a file, would it be useful for them to know?

ls has the ability to distinguish between elements using the -F flag.

On the man page:

 -F, --classify append indicator (one of */=>@|) to entries 

All you have to do is add -F to your ls in your terminal as follows:

 $ ls -F 

You can make this permanent by setting an alias, opening your .bashrc (or similar) file and adding:

alias ls='ls -F'

After setting this option (and logging out, and turning on or running source ~/.bashrc ), you can just run ls and it will always assume that you added -F .

+1
source

add this to your .bashrc or .profile: alias ls = 'ls --color = auto'

0
source

Source: https://habr.com/ru/post/1306563/


All Articles