Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove dir background in `ls -color` output [closed]

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

enter image description here

some dir has green background, How to remove it?

like image 324
chikadance Avatar asked Nov 13 '16 14:11

chikadance


Video Answer


2 Answers

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
like image 134
bloody Avatar answered Oct 12 '22 06:10

bloody


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)"
like image 21
Rafael Kitover Avatar answered Oct 12 '22 07:10

Rafael Kitover