LoginSignup
0
0

More than 5 years have passed since last update.

lsコマンドを入力した時の文字色を変更する方法

Last updated at Posted at 2018-09-01

lsコマンドを入力するとディレクトリ名が読みにくい

最近、CentOS7を使ってサーバー構築などの勉強をしているのですが、lsでディレクトリを表示した時がまー見にくいです。
黒の背景に青文字って……
まともに読もうとしたらマジで目が死にます。
なので、それを変える方法を今回は投稿します。

手順

$ su
# cd /etc
# cp -p DIR_COROLS DIR_COROLS_org  //念のためバックアップファイル作成
# vi DIR_COROLS

以下の部分を/DIRなどと入力して見つけて、編集します。

(前略)
# Below are the color init strings for the basic file types. A color init
# string consists of one or more of the following numeric codes:
# Attribute codes:
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# Background color codes:
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
NORMAL 00 # global default, although everything should be something.
FILE 00 # normal file
DIR 01;34 # directory
LINK 01;36# symbolic link
FIFO 40;33# pipe
SOCK 01;35# socket
BLK 40;33;01# block device driver
CHR 40;33;01# character device driver
ORPHAN 01;05;37;41# orphaned syminks
MISSING 01;05;37;41 # ... and the files they point to
(後略)

エスケープ文のところに丁寧に書かれてるのでそれを読むのが一番ですが、簡潔に言うと
Attribute codesが文字の属性(太字・アンダーラインなど)、
Text color codesが文字色、
Background color codesが背景色となります。
あとは説明されてる通りにコードを編集すれば、大丈夫です。
私は太字をやめて背景を白にしたかったので、DIR 00;34;47としました。
↓こんな感じです。
スクリーンショット 2018-09-01 18.22.54.png
その後に下記コマンドを入力して、ログアウトしてください。
(ログアウト忘れたせいで表示が変わらず、無駄にハマりました…)

# eval 'dircolors /etc/DIR_COLORS -b'  //実行結果が出力されます
# exit
$ exit

ちなみに

Macでは.bashrcに以下を記載すると良い感じになります

.bashrc
alias ls='ls -FG'
export LSCOLORS=gxfxcxdxbxegedabagacad
# 上記を記載後ターミナルで↓
$ source ~/.bashrc

参考:http://d.hatena.ne.jp/edvakf/20080413/1208042916

0
0
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
0
0