How to remove dir background in `ls -color` output

前端 未结 4 1495
情深已故
情深已故 2020-12-29 10:35

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

some dir has green background, How to remove it?

4条回答
  •  既然无缘
    2020-12-29 10:51

    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.

提交回复
热议问题