LoginSignup
1
1

More than 1 year has passed since last update.

WSL2 (Ubuntu 20.04LTS) のターミナルで ls したときのディレクトリの表示色を変える

Last updated at Posted at 2021-10-19

基本、dircolors で変えればいいのだけど、DIR の色を変えても Windows のファイルシステムの色は変わってくれない。OTHER_WRITEBLE を変えるのがポイントっぽい。

手順

WSL2 + Ubuntu 20.04LTS の場合、~/.bashrc~/.dircolors が存在していれば自動的に読み込むようになっているので、~/.colorrc じゃなくて ~/.dircolors にします。

$ dircolors -p > ~/.dircolors
$ vi ~/.dircolors

これで、下記の DIR じゃなくて OTHER_WRITABLE を編集する。01;36 として水色にしてみた。

RESET 0 # reset to "normal" color
DIR 01;34 # directory
LINK 01;36 # symbolic link. (If you set this to 'target' instead of a
 # numerical value, the color is as for the file pointed to.)
MULTIHARDLINK 00 # regular file with more than one link
FIFO 40;33 # pipe
SOCK 01;35 # socket
DOOR 01;35 # door
BLK 40;33;01 # block device driver
CHR 40;33;01 # character device driver
ORPHAN 40;31;01 # symlink to nonexistent file, or non-stat'able file ...
MISSING 00 # ... and the files they point to
SETUID 37;41 # file that is setuid (u+s)
SETGID 30;43 # file that is setgid (g+s)
CAPABILITY 30;41 # file with capability
STICKY_OTHER_WRITABLE 30;42 # dir that is sticky and other-writable (+t,o+w)
OTHER_WRITABLE 01;36 # dir that is other-writable (o+w) and not sticky
STICKY 37;44 # dir with the sticky bit set (+t) and not other-writable

vi で編集すると色の指定を変えると、文字の色がその場で変化するのでわかりやすい。

image.png

こんな感じになる。

これで、

$ source ~/.bashrc

とすれば色が反映される。はず。

色については下記の記事が参考になります。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1