[Linux] 自定義alias指令集 – .bash_aliases

Intro

現今大多 Unix/Linux(包含Mac OS),預設.bashrc會自動引入.bash_aliases:

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

所以我們可以將自定義Alias指令整理至.bash_aliases以方便管理。


alias指令

指令:alias alias-cmd="your custom command here"

建立或修改.bash_aliases範例:

alias current-time="echo 'Current time: $(date)'"

建立之後source ~/.bash_aliases或重新登入,即可使用自定義指令:

$ current-time 
Current time: Fri Nov 26 12:54:14 CST 2021

Leave a Reply

Your email address will not be published. Required fields are marked *