
私のコンソールでは、ディレクトリの色が青すぎるため、暗い背景では読みにくいです。
の色の定義を変更するにはどうすればよいですか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
とても簡単です。次の3行を~/.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 環境変数として使用するのに適した extension:color マッピングのコレクションです。