MacOS 終端機 Terminal 上使用 ll、la、l 指令 (ls -al)


MacOS 終端機 terminal 上使用 ll 指令

習慣在 Linux 上執行 ll 指令,但是在 MacOS 終端機 terminal 上卻沒有,只能用 ls、ls -al 實在很不方便,你可以在 Terminal 加上你的常用別名指令去解決這個問題。

一、選擇「終端機 (terminal)」

二、先進入到 home 的目錄

user@MacBook-Pro ~ % cd ~

三、建立或編輯 .bash_profile

user@MacBook-Pro ~ % vim .bash_profile

四、增加以下別名

alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

五、執行 source

user@MacBook-Pro ~ % source .bash_profile
user@MacBook-Pro ~ % ll

如遇到 no such file or directory 的處理方式

user@MacBook-Pro ~ % ll
zsh: command not found: ll

user@MacBook-Pro % source ~/.bash_profile 
/Users/xxx/.bash_profile:source:1: no such file or directory: /Users/xxx/.profile

先開啟 ~/.bash_profile 檔案,將 source ~/.profile 移除

user@MacBook-Pro ~ % vim .bash_profile
# source ~/.profile  註解掉此行
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# Added by install_latest_perl_osx.pl
[ -r /Users/xxx/.bashrc ] && source /Users/xxx/.bashrc

重新再執行一次 source ~/.bash_profile

user@MacBook-Pro ~ % source .bash_profile
user@MacBook-Pro ~ % ll
total 2304
drwxrwxrwx  1 xxx   staff  131072  1  1  1980 ./
drwxr-xr-x  5 root  wheel     160  2  3 15:56 ../
drwxrwxrwx  1 xxx   staff  131072  3 11  2017 .Spotlight-V100/
drwxrwxrwx  1 xxx   staff  131072  3 15  2017 .TemporaryItems/
drwxrwxrwx  1 xxx   staff  131072  3 11  2017 .Trashes/
drwxrwxrwx  1 xxx   staff  131072  2  3 10:36 .fseventsd/
drwxrwxrwx  1 xxx   staff  131072  1 30 22:23 docker/
drwxrwxrwx  1 xxx   staff  131072  2  3 14:38 hosts/