Skip to content

macOS terminal

ABBR & terms#

see alsoLinux

sh: Unix shell (from Thompson shell) csh: C shell BSD: Berkeley Software Distribution tcsh: enhanced csh, in FreeBSD, its the same as csh .zshrc: will run automatically at startup of terminal

z-shell#

zsh: more commonly accepted abbreviation for z-shell

hotkey#

将光标移动到行首:CONTROL + A 将光标移动到行尾:CONTROL + E 清除屏幕:CONTROL + L 搜索以前使用命令:CONTROL + R 清除当前行:CONTROL + U 清除至当前行尾:CONTROL + K 单词为单位移动:OPTION + 方向键 详见apple 官网

commands#

cmd explanation / meaning
man manual, help. In less read-only mode
pbcopy pb means paste-board [^pb]
pbpaste can copy/ paste a file [^pb]
path global variable
alias global variable, customized commands
export
touch create empty file if not exist.
source NOT! enable customized command.
source run a bash file.
open -e #open with default app
read get input. -q:Y/N ^man-read
diff check file diff, -q -s

[^pb]: e.g.$ pbcopy < ~/.ssh/id_rsa.pub https://docs.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account

Syntax#

FreeBSD Manual. error_handling Z Shell Manual select directories: use */.

logic control#

functions#

Functions in Bash has no return value. Since all the values are golbal, a work around (I currently use) is pass the return value of a function as a global variable.

There is no try/catch in bash; however, one can achieve similar behavior using && or ||.

arguments#
var meaning s
$@ all argin
$1 frist argin
timefmt#

zsh stat timefmt Ymd HMS

stat -t "%Y%m%d%H%M%S" # an example of call , "%Y" also "%0Y", but not "%.Y" Y Year m Month d Date H Hour (0-23) h Hour (1-12) M Minute (0-59) S Seconds (0-59) s Milliseconds (0-999) p text "pm" or "am" P text "PM" or "AM" % The symbol "%"

source1 source2

customized commands#

From Create custom Terminal shortcuts Followed this and FreeBSD Manual

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# !!! deprecated since catalina. !!!
# with  `.bash_profile`
# Add aliases in ~/.bash_profile:
# File .bash_profile may not exist:
touch ~/.bash_profile
# Then add aliases with nano ~/.bash_profile. Examples:
alias newcmd='echo "this is a customized command defined by ~/.bash_profile"'
# Then source the file or restart Terminal.app:
source ~/.bash_profile
# When the terminal starts, automatically `source ~/.bash_profile`
  • .bash_profile is now discarded (since mac terminal use Z shell), it is now .zshrc. .bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.

TODO#

https://www.shellscript.sh/functions.html Advanced Bash-Scripting Guide https://tldp.org/LDP/abs/html/index.html