Skip to main content

管理與操作

查出目前使用哪種 SHELL

ps -p $$
echo $0
echo $SHELL 

執行 SHELL 的方式

sh file
. file
source file

常用鍵盤快捷鍵

Key Operation
Ctrl + a Go to the beginning of the line.
Ctrl + e Go to the end of the line.
Alt + b Go left(back) one word.
Alt + f Go right(forward) one word.
Ctrl + u Cut the part of the line before the cursor, adding it to the clipboard.
Ctrl + k Cut the part of the line after the cursor, adding it to the clipboard.

執行前一個指令的參數

ls -l /home/alang/test.py
vi !$
或
vi <alt> + .

執行前一個指令

!!

搜尋最近曾執行過的指令

<ctrl> + r
(reverse-i-search): 輸入指令開頭的前幾個字元

搜尋所有曾執行過的指令集

$> history | grep "keyword"

新增客製的指令
以下內容需要編輯 ~/.bashrc
- 使用 alias

alias date-time='date && cal'

- 使用 function

date-time () {
    date && cal
    return
}

export -f date-time

客製提示字元 Bash Prompt