开发者

Display Directories with a Bold Font – How to enable? with .bash_profile? [closed]

开发者 https://www.devze.com 2022-12-26 02:50 出处:网络
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a co开发者_运维技巧mment to explain where the question may be able to be answered.

Closed last year.

Improve this question

I'm using a linux server that display directories in a bold font, and files in a normal font.


e.g. $ ls produces

afile.txt afolder anotherfile.txt anotherfolder


I'd like to use this feature on some other servers. How can it be done? with the .bash_profile?

If anyone has other ideas on how to differentiate folders from file, they'd be good to know?


You need to give ls the --colors=… option (e.g. via an alias). To actually configure the LS_COLORS environmental variable used to define the colours, one good way is to create a configuration file for dircolors, e.g. with just bold (attribute 1) directories:

echo DIR 1 >~/.dir_colors

Then in your .bash_profile or .bashrc, eval the output of dircolors run on that file to set LS_COLORS according to your configuration. The relevant 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, by default, display the bold attribute as true bold but rather just use a brighter colour. You need to configure your terminal to get real bold.

See the dircolors --print-database for an example of a “complete” configuration file.


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


If anyone has other ideas on how to differentiate folders from file, they'd be good to know?

ls does have the ability to differentiate items using the -F flag.

From the man page:

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

All you have to do is add -F to your ls command in your terminal like so:

$ ls -F

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

alias ls='ls -F'

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


See the man page for ls, the -F option as was said above gives you probably what you need to readily see which names are folders, executables and symbolic links. And see the -G option to color the files you can also use both. I guess it's so simple, I wouldn't bother to put it in an alias. You can also use both to get the two effects at the same time.

ls -F -G

ls -FG


It's done with an environment variable. Start with reading the ls man page:

$ man ls

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号