4種繞過Linux/Unix命令別名的方法
我在我的 Linux 系統(tǒng)上定義了如下 mount
別名:
alias mount='mount | column -t'
但是我需要在掛載文件系統(tǒng)和其他用途時繞過這個 bash 別名。我如何在 Linux、*BSD、macOS 或者類 Unix 系統(tǒng)上臨時禁用或者繞過 bash shell 呢?
你可以使用 alias
命令定義或顯示 bash shell 別名。一旦創(chuàng)建了 bash shell 別名,它們將優(yōu)先于外部或內(nèi)部命令。本文將展示如何暫時繞過 bash 別名,以便你可以運行實際的內(nèi)部或外部命令。
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
命令調(diào)用實際的 /bin/mount
:
"mount"
或者
'mount'
方法 3 - 使用命令的完全路徑
使用完整的二進制路徑,如 /bin/mount
:
/bin/mount
/bin/mount /dev/sda1 /mnt/sda
方法 4 - 使用內(nèi)部命令 command
語法是:
command cmd
command cmd arg1 arg2
要覆蓋 .bash_aliases
中設(shè)置的別名,例如 mount
:
command mount
command mount /dev/sdc /mnt/pendrive/
“command” 直接運行命令或顯示關(guān)于命令的信息。它帶參數(shù)運行命令會抑制 shell 函數(shù)查詢或者別名,或者顯示有關(guān)給定命令的信息。
關(guān)于 unalias 命令的說明
要從當(dāng)前會話的已定義別名列表中移除別名,請使用 unalias
命令:
unalias mount
要從當(dāng)前 bash 會話中刪除所有別名定義:
unalias -a
確保你更新你的 ~/.bashrc
或 $HOME/.bash_aliases
。如果要***刪除定義的別名,則必須刪除定義的別名:
vi ~/.bashrc
或者
joe $HOME/.bash_aliases
想了解更多信息,參考這里的在線手冊,或者輸入下面的命令查看:
man bash
help command
help unalias
help alias