温馨提示×

ubuntu aliases有啥好处

小樊
52
2026-09-02 10:14:58
栏目: 智能运维

在 Ubuntu(以及其它 Linux 发行版)里,alias(别名) 主要是用来给命令“起外号”的,好处还挺多的,常见有这么几类:

1. 省时间、敲命令更快

把又长又常用的命令变短:

alias ll='ls -alF'
alias gs='git status'

本来要敲 git status,现在 gs 就完事。

2. 避免重复输入复杂参数

很多命令参数记不住或太长:

alias update='sudo apt update && sudo apt upgrade -y'

一句 update 直接系统升级。

3. 减少出错概率

把容易敲错的命令固定下来:

alias rm='rm -i'

删除前先确认,防止误删。

4. 统一使用习惯

比如你习惯用 grep --color=auto,可以直接:

alias grep='grep --color=auto'

不用每次都加参数。

5. 个性化工作环境

不同人可以有不同风格:

alias py='python3'
alias ..='cd ..'
alias ...='cd ../..'

6. 临时“封印”危险命令(也算一种保护)

alias reboot='echo "别乱重启"'

小提醒

  • 当前终端有效:直接在终端敲 alias xxx='...'
  • 永久生效:写进
    • ~/.bashrc(bash 用户)
    • ~/.zshrc(zsh 用户)
  • 查看已有 alias:alias
  • 取消 alias:unalias 名字

如果你愿意,我也可以帮你配一套实用的 Ubuntu alias 清单。

0 踩