如何删除`ls -color`输出中的目录背景 [英] How to remove dir background in `ls -color` output

查看:23
本文介绍了如何删除`ls -color`输出中的目录背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用默认的 Linux Mint .bashrc,这里是

某些目录有绿色背景,如何删除?

解决方案

快速解决方案:

在 Bash 命令行中输入这两个命令:

dircolors -p |sed 's/;42/;01/' >~/.dircolors源 ~/.bashrc

<小时>

说明:

有一个程序 dircolors 旨在为 ls 设置配置.默认的 ~/.bashrc 脚本使用以下几行加载配置:

# 启用 ls 的颜色支持并添加方便的别名如果 [ -x/usr/bin/dircolors ];然后test -r ~/.dircolors &&eval "$(dircolors -b ~/.dircolors)" ||eval "$(dircolors -b)"

因为默认情况下 ~/.dircolors 文件实际上并不存在,脚本使用内置的 Bash 配置 (eval "$(dircolors -b)").

去除o+w的绿色背景(在drwxrwxrwx符号中最后一个'w'标记为'writable by others'权限code>ls) 目录,您需要根据当前(内置)配置创建此文件.在命令行中输入以下内容:

dircolors -p >~/.dircolors

dircolor -p 打印当前配置,> 将输出重定向到给定文件.

现在在编辑器中打开文件并找到以下行:

OTHER_WRITABLE 34;42 # 其他可写 (o+w) 且不粘的目录

将数字42(表示绿色背景)更改为01(无背景)并保存更改.或者,您可以直接从命令行使用 sed 程序及其替换功能('s/PATTERN/NEW_STRING/' 语法)来完成:

sed -i 's/;42/;01/' ~/.dircolors

通过使用管道'|'的单个命令可以实现以上2件事:

dircolors -p |sed 's/;42/;01/' >~/.dircolors

要使更改生效(无需重新启动 shell),请键入:

source ~/.bashrc

I use default Linux Mint .bashrc, here is full bashrc, the output is like:

some dir has green background, How to remove it?

解决方案

Quick solution:

Enter these two commands in the Bash command line:

dircolors -p | sed 's/;42/;01/' > ~/.dircolors
source ~/.bashrc


Explanation:

There is a program dircolors intended to set up the config for ls. The default ~/.bashrc script loads the config with these lines:

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"

Because by default the file ~/.dircolors does not actually exist the script uses the built-in Bash config (eval "$(dircolors -b)").

To remove green background for o+w ('writable by others' permission marked by last 'w' in drwxrwxrwx notation in ls) directories you need to create this file basing on the current (built-in) config. In the command line type the following:

dircolors -p > ~/.dircolors

dircolor -p prints the current config and > redirects the output to the given file.

Now open the file in an editor and find the following line:

OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky

change the number 42 (denoting green background) to 01 (no background) and save changes. Alternatively you can do it with sed program and its substitution feature ('s/PATTERN/NEW_STRING/' syntax) from the command line directly:

sed -i 's/;42/;01/' ~/.dircolors

Above 2 things can be achieved by a single command using a pipe '|':

dircolors -p | sed 's/;42/;01/' > ~/.dircolors

To get the change to take the effect (without restarting the shell), type:

source ~/.bashrc

这篇关于如何删除`ls -color`输出中的目录背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆