macOS で ls
コマンドの出力結果に色を付けるには ls -G
または ls --color
を実行します。 利用可能な設定は man ls
で下記のように記載されていました。 今回は Ventura (13.4.1) 環境、且つ bash で確認しました。
The value of this variable describes what color to use for which attribute when colors are enabled with CLICOLOR or
COLORTERM. This string is a concatenation of pairs of the format fb, where f is the foreground color and b is the
background color.
The color designators are as follows:
a black
b red
c green
d brown
e blue
f magenta
g cyan
h light grey
A bold black, usually shows up as dark grey
B bold red
C bold green
D bold brown, usually shows up as yellow
E bold blue
F bold magenta
G bold cyan
H bold light grey; looks like bright white
x default foreground or background
Note that the above are standard ANSI colors. The actual display may differ depending on the color capabilities of
the terminal in use.
The order of the attributes are as follows:
- directory
- symbolic link
- socket
- pipe
- executable
- block special
- character special
- executable with setuid bit set
- executable with setgid bit set
- directory writable to others, with sticky bit
- directory writable to others, without sticky bit
The default is "exfxcxdxbxegedabagacad", i.e., blue foreground and default background for regular directories, black
foreground and red background for setuid executables, etc.
デフォルトでは 1 = e = blue
になっており、私の環境ではやや見づらいです (ターミナルの背景が黒だと、ディレクトリの「濃い青」が見づらいです)。
これを変更する場合は ~/.bash_profile
等に下記のように設定します。 先頭 (1) を g
(cyan) へ変更しています。
export LSCOLORS=gxfxcxdxbxegedabagacad
これで以下のように変更され、私の環境 = 背景が黒でもディレクトリが見やすくなりました。
コメント