bash 用粗体显示目录 - 如何启用?使用 .bash_profile?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2613662/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 21:56:12  来源:igfitidea点击:

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

linuxbashunix

提问by Ross

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

我使用的 linux 服务器以粗体显示目录,并以普通字体显示文件。



e.g. $ lsproduces

例如$ ls产生

afile.txt afolderanotherfile.txt anotherfolder

afile.txt afolderanotherfile.txt anotherfolder



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

我想在其他一些服务器上使用此功能。怎么做到呢?与.bash_profile?

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

如果有人对如何区分文件夹和文件有其他想法,他们会很高兴知道吗?

回答by Arkku

You need to give lsthe --colors=…option (e.g. via an alias). To actually configure the LS_COLORSenvironmental 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:

你需要给ls--colors=…选项(例如,通过一个别名)。要实际配置LS_COLORS用于定义颜色的环境变量,一种好方法是为dircolors,例如仅使用粗体(属性 1)目录创建配置文件:

echo DIR 1 >~/.dir_colors

Then in your .bash_profileor .bashrc, evalthe output of dircolorsrun on that file to set LS_COLORSaccording to your configuration. The relevant lines in my .bashrc(copied from somewhere) look like this:

然后在您的.bash_profileor 中.bashrc,根据您的配置在该文件evaldircolors运行的输出进行设置LS_COLORS。我.bashrc(从某处复制)中的相关行如下所示:

  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-databasefor an example of a “complete” configuration file.

有关dircolors --print-database“完整”配置文件的示例,请参见。

回答by synkro

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

将此添加到您的 .bashrc 或 .profile: alias ls='ls --color=auto'

回答by synkro

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

如果有人对如何区分文件夹和文件有其他想法,他们会很高兴知道吗?

lsdoes have the ability to differentiate items using the -Fflag.

ls确实有能力使用-F标志区分项目。

From the man page:

手册页

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

All you have to do is add -Fto your lscommand in your terminal like so:

您所要做的就是在终端中添加-F到您的ls命令中,如下所示:

$ ls -F

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

您可以通过打开您的.bashrc(或类似的)文件并添加以下内容来设置别名,从而使其永久化:

alias ls='ls -F'

alias ls='ls -F'

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

设置后(以及注销并重新启动或运行source ~/.bashrc),您可以简单地运行ls,它会始终假设您添加了-F.

回答by Paul Beckingham

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

它是通过环境变量完成的。首先阅读 ls 手册页:

$ man ls

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

您可能无法仅使用粗体,而只能使用特定颜色进行粗体。