Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Linux 別名配置:讓高頻指令一鍵直達

編輯:Linux 教學

每次輸入冗長指令既慢又易錯,將常用指令定義為別名寫入 /etc/profile(全域)或 ~/.bashrc(用戶級),登入即時生效。

編輯配置檔

vi /etc/profile
# 或
vi ~/.bashrc

常用別名範例

alias ws='cd /opt/workspace'
alias pjava="ps -ef | grep java"
alias ktomcat="ps -ef | grep ./apache-tomcat | grep -v grep | awk '{print $2}' | xargs kill -9"
alias tlog="tail -f /var/log/api/data/api.log"
  • ws:快速進入工作目錄。
  • pjava:查看 Java 進程。
  • ktomcat:暴力殺掉 Tomcat 進程(awk '{print $2}' 取 PID 更穩健)。
  • tlog:即時追蹤 API 日誌。

立即生效

source /etc/profile
# 或
source ~/.bashrc

進階技巧

  • 帶參數別名需用函數:function mygrep() { grep -r "$1" /path/to/log; }
  • 查看所有別名:alias 或 alias -p。
  • 臨時取消別名:unalias name(僅當前 Shell 有效)。
Copyright © Windows教程網 All Rights Reserved