學習足跡

2012年11月27日 星期二

Linux CLI 提示字元的設定

提示字元變數名稱:PS1(1為數字1)

參數(鳥哥:認識與學習 BASH):


  • \d :可顯示出『星期 月 日』的日期格式,如:"Mon Feb 2"
  • \H :完整的主機名稱。舉例來說,鳥哥的練習機為『www.vbird.tsai』
  • \h :僅取主機名稱在第一個小數點之前的名字,如鳥哥主機則為『www』後面省略
  • \t :顯示時間,為 24 小時格式的『HH:MM:SS』
  • \T :顯示時間,為 12 小時格式的『HH:MM:SS』
  • \A :顯示時間,為 24 小時格式的『HH:MM』
  • \@ :顯示時間,為 12 小時格式的『am/pm』樣式
  • \u :目前使用者的帳號名稱,如『root』;
  • \v :BASH 的版本資訊,如鳥哥的測試主機版本為 3.2.25(1),僅取『3.2』顯示
  • \w :完整的工作目錄名稱,由根目錄寫起的目錄名稱。但家目錄會以 ~ 取代;
  • \W :利用 basename 函數取得工作目錄名稱,所以僅會列出最後一個目錄名。
  • \# :下達的第幾個指令。
  • \$ :提示字元,如果是 root 時,提示字元為 # ,否則就是 $ 囉~


顏色(Color Bash Prompt):



  • txtblk='\e[0;30m' # Black - Regular
  • txtred='\e[0;31m' # Red
  • txtgrn='\e[0;32m' # Green
  • txtylw='\e[0;33m' # Yellow
  • txtblu='\e[0;34m' # Blue
  • txtpur='\e[0;35m' # Purple
  • txtcyn='\e[0;36m' # Cyan
  • txtwht='\e[0;37m' # White
  • bldblk='\e[1;30m' # Black - Bold
  • bldred='\e[1;31m' # Red
  • bldgrn='\e[1;32m' # Green
  • bldylw='\e[1;33m' # Yellow
  • bldblu='\e[1;34m' # Blue
  • bldpur='\e[1;35m' # Purple
  • bldcyn='\e[1;36m' # Cyan
  • bldwht='\e[1;37m' # White
  • unkblk='\e[4;30m' # Black - Underline
  • undred='\e[4;31m' # Red
  • undgrn='\e[4;32m' # Green
  • undylw='\e[4;33m' # Yellow
  • undblu='\e[4;34m' # Blue
  • undpur='\e[4;35m' # Purple
  • undcyn='\e[4;36m' # Cyan
  • undwht='\e[4;37m' # White
  • bakblk='\e[40m'   # Black - Background
  • bakred='\e[41m'   # Red
  • bakgrn='\e[42m'   # Green
  • bakylw='\e[43m'   # Yellow
  • bakblu='\e[44m'   # Blue
  • bakpur='\e[45m'   # Purple
  • bakcyn='\e[46m'   # Cyan
  • bakwht='\e[47m'   # White
  • txtrst='\e[0m'    # Text Reset



Prompt escapes



  • \a an ASCII bell character (07)
  • \d the date in "Weekday Month Date" format (e.g., "Tue May 26")
  • \D{format} the format is passed to strftime(3) and the result
  •  is inserted into the prompt string an empty format
  •  results in a locale-specific time representation.
  •  The braces are required
  • \e an ASCII escape character (033)
  • \h the hostname up to the first `.'
  • \H the hostname
  • \j the number of jobs currently managed by the shell
  • \l the basename of the shell's terminal device name
  • \n newline
  • \r carriage return
  • \s the name of the shell, the basename of $0 (the portion following
  •  the final slash)
  • \t the current time in 24-hour HH:MM:SS format
  • \T the current time in 12-hour HH:MM:SS format
  • \@ the current time in 12-hour am/pm format
  • \A the current time in 24-hour HH:MM format
  • \u the username of the current user
  • \v the version of bash (e.g., 2.00)
  • \V the release of bash, version + patch level (e.g., 2.00.0)
  • \w the current working directory, with $HOME abbreviated with a tilde
  • \W the basename of the current working directory, with $HOME
  • abbreviated with a tilde
  • \! the history number of this command
  • \# the command number of this command
  • \$ if the effective UID is 0, a #, otherwise a $
  • \nnn the character corresponding to the octal number nnn
  • \\ a backslash
  • \[ begin a sequence of non-printing characters, which could be used
  •  to embed a terminal control sequence into the prompt
  • \] end a sequence of non-printing characters



沒有留言:

張貼留言