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.
Alt + . Use the last word of the previous command.
Ctrl + r Search through the command's history
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.
Ctrl + l Clear the screen
Ctrl + w 刪除游標前個單字
Ctrl+x,Ctrl+e Edit the current command in your $EDITOR.


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




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


$> history | grep "keyword"
Alias - 新增客製的指令

以下內容需要編輯 ~/.bashrc
- 使用 alias

# User specific aliases and functions
alias date-time='date && cal'

- 使用 function

date-time () {
    date && cal

export -f date-time

- 常用 Aliases

# Custom specified aliases
alias lastmod="find . -type f -exec stat --format '%Y :%y %n' \"{}\" \; | sort -nr | cut -d: -f2-"
alias vi="vim"
alias grep="grep --color"
Bash Prompt - 客製提示字元
Formatting Scripts
# Install shfmt
## On Ubuntu
sudo snap install shfmt
## On Alpine Linux
sudo apk add shfmt
## On FreeBSD
sudo pkg install devel/shfmt

# Format shell programs using Shfmt
## -i flag is the amount of spaces that will be used to intend.
shfmt -i 4
## With Diff style output
shfmt -d -i 4
# 1. script
# Once you are done with the session, type the 'exit'.
script my.out

# 2. tee
myprogram | tee my.out