问题
I use default Linux Mint .bashrc, here is full bashrc, the output is like:
some dir has green background, How to remove it?
回答1:
To remove all background colors, stick the following into your ~/.bashrc :
eval "$(dircolors -p | \
sed 's/ 4[0-9];/ 01;/; s/;4[0-9];/;01;/g; s/;4[0-9] /;01 /' | \
dircolors /dev/stdin)"
回答2:
The explanation is given in the output of dircolors -p
, e.g.,
Of course dircolors
doesn't color its output. I used this script:
#!/usr/bin/perl -w
use strict;
our $comment = "\e[31m";
our $reset = "\e[K\e[m";
our @data;
open my $fh, "dircolors -p|" or die "cannot read from dircolors";
@data = <$fh>;
close $fh;
printf "\e[H\e[2J";
for my $n ( 0 .. $#data ) {
chomp $data[$n];
if ( $data[$n] =~ /^\s*#/ ) {
printf "%s%s%s\n", $comment, $data[$n], $reset;
}
elsif ( $data[$n] =~ /^\s*TERM\s/ ) {
printf "%s\n", $data[$n];
}
elsif ( $data[$n] =~ /^\s*[^\s]+\s+\d+(;\d+)?\s*(#.*)?$/ ) {
my $code = $data[$n];
$code =~ s/^\s*[^\s]+\s+//;
$code =~ s/\s.*//;
my $data = $data[$n];
$data =~ s/(#.*)$/$comment$1$reset/;
$data =~ s/^(\s*)([^\s]+)(\s+)/$1\e[${code}m$2\e[m$3/;
printf "%s\n", $data;
}
else {
printf "%s\n", $data[$n];
}
}
1;
To get rid of the background, you can either change the directory permissions, or use a different database to set your LS_COLORS
environment variable. The dircolors documentation is the place to go.
来源:https://stackoverflow.com/questions/40574819/how-to-remove-dir-background-in-ls-color-output