61
59

More than 5 years have passed since last update.

Linuxのプロンプトの表示を変更する

Posted at

Linuxにログインすると出てくる以下ような表示がプロンプト。これの表記の変更をする。

[hoge@fuga ~]$

設定ファイルを開いて値を変更

$ vim ~/.bashrc

ファイルの1行目のPS1=となっているところを変更して表記を変える。とりあえずtest-app2となっているところをperaichi-app2に変更してみた。

Before

~/.bashrc
PS1='\[\e[36m\]test-app2 \[\e[33m\]\t \[\e[31m]'

スクリーンショット 2015-06-05 8.51.19.png

After

~/.bashrc
PS1='\[\e[36m\]peraichi-app2 \[\e[33m\]\t \[\e[31m]'

スクリーンショット 2015-06-05 8.52.38.png

設定値や色など

以下のように表示したい設定値を入れておくと、自由に変えられる。

設定値

\d : 日付
\h : ホスト名(ドメイン名なし)
\H : ホスト名(ドメイン名あり)
\s : シェルの名前
\t : 時間(24時間制 HH:MM:SS形式)
\T : 時間(12時間制 HH:MM:SS形式)
\@ : 時間(12時間制 HH:MM AM/PM形式)
\u : ユーザ名
\w : カレントディレクトリ
\W : カレントディレクトリのベース名
! : コマンドの履歴番号を表示
# : コマンドのコマンド番号
\$ : rootなら#、それ以外のユーザなら$を表示
\ : バックスラッシュ

0;30m Black
0;31m Red
0;32m Green
0;33m Yellow
0;34m Blue
0;35m Purple
0;36m Cyan
0;37m White

61
59
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
61
59