🐡
【Linux】エイリアスを一時的に無効にしたい
1. エイリアスを一時的に無効化する方法は3つ
以下の3つです。
1つ目の方法は、記述する量が少なくて済むので、私が使うとしたらこれです。
(逆に、後ろ2つはこの記事を書く過程で知りました)
2. 実際にエイリアスを一時的に無効化してみます
lsと入力すると、自動的にls -laが実行されるエイリアスが設定されているとします。
[root@ora19_rh88 ~]# type ls
ls は `ls -la' のエイリアスです
[root@ora19_rh88 ~]#
[root@ora19_rh88 ~]# ls
合計 44
dr-xr-x---. 4 root root 4096 4月 13 09:59 .
dr-xr-xr-x. 18 root root 238 4月 13 02:09 ..
-rw-------. 1 root root 235 4月 13 09:59 .Xauthority
-rw-------. 1 root root 5795 4月 13 09:43 .bash_history
-rw-r--r--. 1 root root 18 8月 13 2018 .bash_logout
-rw-r--r--. 1 root root 176 8月 13 2018 .bash_profile
-rw-r--r--. 1 root root 176 8月 13 2018 .bashrc
drwx------. 3 root root 19 4月 13 00:15 .cache
-rw-r--r--. 1 root root 100 8月 13 2018 .cshrc
drwx------. 3 root root 25 4月 13 00:15 .dbus
-rw-r--r--. 1 root root 129 8月 13 2018 .tcshrc
-rw-------. 1 root root 1371 4月 13 00:12 anaconda-ks.cfg
-rw-r--r--. 1 root root 1818 4月 13 00:19 initial-setup-ks.cfg
[root@ora19_rh88 ~]#
2-1. コマンドの冒頭に「\」を記述する
[root@ora19_rh88 ~]# \ls
anaconda-ks.cfg initial-setup-ks.cfg
[root@ora19_rh88 ~]#
2-2. フルパスで指定する
lsコマンドのパスが分からなかったので、whichコマンドで探してから実行しています。
[root@ora19_rh88 ~]# which ls
alias ls='ls -la'
/usr/bin/ls
[root@ora19_rh88 ~]#
[root@ora19_rh88 ~]# /usr/bin/ls
anaconda-ks.cfg initial-setup-ks.cfg
[root@ora19_rh88 ~]#
2-3. コマンドの前に、「command」を追加する
[root@ora19_rh88 ~]# command ls
anaconda-ks.cfg initial-setup-ks.cfg
[root@ora19_rh88 ~]#
Discussion
細かい話をすれば、どれもエイリアスを無効にしているわけではないんですけどね。
定義されたエイリアスの名前は
lsです。つまり最初の単語が
lsでなければ、エイリアス展開は行われません。\lsはlsではありません。/usr/bin/lsはlsではありません。commandはlsではありません。ということで、どれも
lsではないので、lsのエイリアス展開が発動しないだけです。なので
l\sでも良いし"ls"良いし、ls""でも構いません。env lsというのもあります。lsではない単語でlsが呼び出せれば良いだけなんです。シェルによっては
alias '\ls=date'のようなエイリアスを定義することができます。この場合\lsと実行するとエイリアスが展開が行われます。冒頭の\にエイリアスを無効にするという意味はないので。