4 种绕过 Linux/Unix 命令别名的方法

2018-03-02 22:45


我在我的 Linux 系统上定义了如下 mount 别名:

alias mount='mount | column -t'

但是我需要在挂载文件系统和其他用途时绕过这个 bash 别名。我如何在 Linux、*BSD、macOS 或者类 Unix 系统上临时禁用或者绕过 bash shell 呢?

你可以使用 alias 命令定义或显示 bash shell 别名。一旦创建了 bash shell 别名,它们将优先于外部或内部命令。本文将展示如何暂时绕过 bash 别名,以便你可以运行实际的内部或外部命令。

4 种绕过 bash 别名的方法

尝试以下任意一种方法来运行被 bash shell 别名绕过的命令。让我们如下定义一个别名

alias mount='mount | column -t'

运行如下:

mount

示例输出:

sysfs                        on  /sys                             type  sysfs            (rw,nosuid,nodev,noexec,relatime)
proc                         on  /proc                            type  proc             (rw,nosuid,nodev,noexec,relatime)
udev                         on  /dev                             type  devtmpfs         (rw,nosuid,relatime,size=8023572k,nr_inodes=2005893,mode=755)
devpts                       on  /dev/pts                         type  devpts           (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs                        on  /run                             type  tmpfs            (rw,nosuid,noexec,relatime,size=1610240k,mode=755)
/dev/mapper/ubuntu--vg-root  on  /                                type  ext4             (rw,relatime,errors=remount-ro,data=ordered)
/dev/sda1                    on  /boot                            type  ext4             (rw,relatime,data=ordered)
binfmt_misc                  on  /proc/sys/fs/binfmt_misc         type  binfmt_misc      (rw,relatime)
lxcfs                        on  /var/lib/lxcfs                   type  fuse.lxcfs       (rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other)

方法 1 - 使用 \command

输入以下命令暂时绕过名为 mount 的 bash 别名:

\mount

方法 2 - 使用 "command"'command'

如下引用 mount 命令调用实际的 /bin/mount

"mount"

或者

'mount'

方法 3 - 使用命令的完全路径

使用完整的二进制路径,如 /bin/mount

/bin/mount
/bin/mount /dev/sda1 /mnt/sda

方法 4 - 使用内部命令 command

语法是:

command cmd
command cmd arg1 arg2

要覆盖 .bash_aliases 中设置的别名,例如 mount

command mount
command mount /dev/sdc /mnt/pendrive/

“command” 直接运行命令或显示关于命令的信息。它带参数运行命令会抑制 shell 函数查询或者别名,或者显示有关给定命令的信息。

关于 unalias 命令的说明

要从当前会话的已定义别名列表中移除别名,请使用 unalias 命令:

unalias mount

要从当前 bash 会话中删除所有别名定义:

unalias -a

确保你更新你的 ~/.bashrc$HOME/.bash_aliases。如果要永久删除定义的别名,则必须删除定义的别名:

vi ~/.bashrc

或者

joe $HOME/.bash_aliases

想了解更多信息,参考这里的在线手册,或者输入下面的命令查看:

man bash
help command
help unalias
help alias

via: https://www.cyberciti.biz/faq/bash-bypass-alias-command-on-linux-macos-unix/

作者:Vivek Gite 译者:geekpi 校对:wxy

本文由 LCTT 原创编译,Linux中国 荣誉推出