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


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

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

  1. alias mount='mount | column -t'

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

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

4 种绕过 bash 别名的方法

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

  1. alias mount='mount | column -t'

运行如下:

  1. mount

示例输出:

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

方法 1 - 使用 \command

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

  1. \mount

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

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

  1. "mount"

或者

  1. 'mount'

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

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

  1. /bin/mount
  2. /bin/mount /dev/sda1 /mnt/sda

方法 4 - 使用内部命令 command

语法是:

  1. command cmd
  2. command cmd arg1 arg2

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

  1. command mount
  2. command mount /dev/sdc /mnt/pendrive/

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

关于 unalias 命令的说明

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

  1. unalias mount

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

  1. unalias -a

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

  1. vi ~/.bashrc

或者

  1. joe $HOME/.bash_aliases

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

  1. man bash
  2. help command
  3. help unalias
  4. help alias 

相关内容