콘솔에서 ls를 사용하여 디렉토리 색상을 어떻게 변경합니까?

콘솔에서 ls를 사용하여 디렉토리 색상을 어떻게 변경합니까?

내 콘솔에서는 디렉토리 색상이 너무 파란색이어서 어두운 배경에서는 읽기가 어렵습니다.

에 대한 색상 정의를 어떻게 변경할 수 있습니까 ls?

답변1

디렉터리 색상을 변경하려면 ~/.bashrc편집기로 파일을 여세요.

nano ~/.bashrc

파일 끝에 다음 항목을 작성하십시오.

LS_COLORS=$LS_COLORS:'di=0;35:' ; export LS_COLORS

몇 가지 좋은 색상 선택(이 경우 0;35보라색)은 다음과 같습니다.

Blue = 34
Green = 32
Light Green = 1;32
Cyan = 36
Red = 31
Purple = 35
Brown = 33
Yellow = 1;33
Bold White = 1;37
Light Grey = 0;37
Black = 30
Dark Grey= 1;30

첫 번째 숫자는 스타일(1=굵게)이고 그 뒤에 세미콜론이 붙은 다음 실제 색상 번호입니다. 가능한 스타일(효과)은 다음과 같습니다.

0   = default colour
1   = bold
4   = underlined
5   = flashing text (disabled on some terminals)
7   = reverse field (exchange foreground and background color)
8   = concealed (invisible)

가능한 배경:

40  = black background
41  = red background
42  = green background
43  = orange background
44  = blue background
45  = purple background
46  = cyan background
47  = grey background
100 = dark grey background
101 = light red background
102 = light green background
103 = yellow background
104 = light blue background
105 = light purple background
106 = turquoise background
107 = white background

가능한 모든 색상:

30  = black
31  = red
32  = green
33  = orange
34  = blue
35  = purple
36  = cyan
37  = grey
90  = dark grey
91  = light red
92  = light green
93  = yellow
94  = light blue
95  = light purple
96  = turquoise
97  = white

이러한 매개변수는 다음과 같이 결합될 수도 있습니다.

di=1;4;31;42

LS_COLORS 변수에서 디렉토리는 녹색 배경에 굵은 밑줄이 그어진 빨간색 텍스트로 표시됩니다!

터미널에서 이러한 모든 색상과 스타일을 테스트하려면 다음 중 하나를 사용할 수 있습니다.

for i in 00{2..8} {0{3,4,9},10}{0..7}
do echo -e "$i \e[0;${i}mSubdermatoglyphic text\e[00m  \e[1;${i}mSubdermatoglyphic text\e[00m"
done

for i in 00{2..8} {0{3,4,9},10}{0..7}
do for j in 0 1
   do echo -e "$j;$i \e[$j;${i}mSubdermatoglyphic text\e[00m"
   done
done

ls 명령을 사용할 때 다음과 같이 각 종류를 정의하여 다른 종류의 파일을 변경할 수도 있습니다.

bd = (BLOCK, BLK)   Block device (buffered) special file
cd = (CHAR, CHR)    Character device (unbuffered) special file
di = (DIR)  Directory
do = (DOOR) [Door][1]
ex = (EXEC) Executable file (ie. has 'x' set in permissions)
fi = (FILE) Normal file
ln = (SYMLINK, LINK, LNK)   Symbolic link. If you set this to ‘target’ instead of a numerical value, the color is as for the file pointed to.
mi = (MISSING)  Non-existent file pointed to by a symbolic link (visible when you type ls -l)
no = (NORMAL, NORM) Normal (non-filename) text. Global default, although everything should be something
or = (ORPHAN)   Symbolic link pointing to an orphaned non-existent file
ow = (OTHER_WRITABLE)   Directory that is other-writable (o+w) and not sticky
pi = (FIFO, PIPE)   Named pipe (fifo file)
sg = (SETGID)   File that is setgid (g+s)
so = (SOCK) Socket file
st = (STICKY)   Directory with the sticky bit set (+t) and not other-writable
su = (SETUID)   File that is setuid (u+s)
tw = (STICKY_OTHER_WRITABLE)    Directory that is sticky and other-writable (+t,o+w)
*.extension =   Every file using this extension e.g. *.rpm = files with the ending .rpm

더 완전한 목록은 다음에서 확인할 수 있습니다.Bigsoft - LS_COLORS 구성.

ow일부 배포판에서는 "( OTHER_WRITABLE) 기본값을 읽을 수 없음"의 배경색을 녹색 배경의 굵은 파란색 텍스트로 변경할 수도 있습니다 .

LS_COLORS="$LS_COLORS:di=1;33"예를 들어 파일 끝 부분에 .bashrc검정색 배경에 읽기 쉽고 굵은 주황색 텍스트를 표시하는 데 사용할 수 있습니다 .

.bashrc 파일을 변경한 후 변경 사항을 적용하려면 셸을 다시 시작하거나 source ~/.bashrc.

참고: 더 많은 명령을콜론, 예를 들어

LS_COLORS=$LS_COLORS:'di=1;33:ln=36' ; export LS_COLORS; ls

원천:

답변2

매우 간단합니다. ~/.bashrc에 다음 세 줄을 추가하세요.

$ vi ~/.bashrc
export LS_OPTIONS='--color=auto'
eval "$(dircolors -b)"
alias ls='ls $LS_OPTIONS'

실행 중인 bash 세션에 변경 사항을 적용하려면 다음을 실행하세요.

source ~/.bashrc

답변3

Hegazi의 답변에 더해 실제로 dircolors 명령을 사용하여 디렉토리 색상과 다른 많은 색상을 제어할 수 있습니다. 잘 문서화되어 있는 구성 파일을 만들 수 있습니다.

다음과 같이 홈 디렉터리에 .dircolor 파일을 만들 수 있습니다.

dircolors -p > ~/.dircolors

그런 다음 ~/.bashrc 파일에 다음 줄을 추가하세요.

eval "`dircolors -b ~/.dircolors`"
alias ls='ls --color=auto'

그러면 bash에 대한 $LS_COLORS 변수가 생성됩니다. csh의 경우 -c 플래그가 설정됩니다. 또한 ls 명령에 플래그를 지정하여 색상으로 표시합니다.

~/.dircolor 파일 색상에서 위와 같이 DIR 속성 값을 편집하여 디렉토리 색상(또는 다른 색상에 포함된 다른 파일 유형)을 변경합니다. 특정 파일의 색상을 변경하거나 직접 정의할 수도 있습니다.

답변4

LS_COLORS

이것은 LS COLORS 환경 변수로 사용하기에 적합한 확장:색상 매핑 모음입니다.

관련 정보