本文共 1402 字,大约阅读时间需要 4 分钟。
hash命令:显示、添加或清除哈希表
root@redhat ~]# hash //输入hash或hash -l 可以查看hash表的内容,我刚开机所以为空hash: hash table empty[root@redhat ~]# hash -lhash: hash table empty
##当我执行过2条命令后再看:[root@redhat ~]# hash //hash表会记录下执行该命令的次数,以及命令的绝对路径hits command1 /bin/cat1 /bin/ls[root@redhat ~]# hash -l //加参数-l既可以看到hash表命令的路径,也可以看到它的名字,说不定会有别名哦builtin hash -p /bin/cat catbuiltin hash -p /bin/ls ls
[root@redhat ~]# hash -p /bin/ls bb //添加hash表,可以看到我把ls命令重新写了一遍,改名为bb[root@redhat ~]# bb //当我执行bb时就是执行ls命令anaconda-ks.cfg icmp_echo_ignore_aly~ pub.keydead.letter icmp_echo_ignore_alz~ rpmbuildicmp_echo_ignore_all~ install.log RPM-GPG-KEY-useraddicmp_echo_ignore_alw~ install.log.syslog RPM-GPG-KEY-westosicmp_echo_ignore_alx~ passwd
[root@redhat ~]# hash -t ls //-t参数可以查看hash表中命令的路径,要是hash表中没有怎么办?/bin/ls[root@redhat ~]# hash -t df //我没使用过df,执行hash,就会提示找不到该命令-bash: hash: df: not found
[root@redhat ~]# hash -r //清楚hash表,清楚的是全部的[root@redhat ~]# hash -lhash: hash table empty
[root@redhat ~]# hash -lbuiltin hash -p /bin/cat catbuiltin hash -p /bin/ls ls[root@redhat ~]# hash -d cat //清楚其中的某一条[root@redhat ~]# hash -lbuiltin hash -p /bin/ls ls
转载于:https://blog.51cto.com/wutengfei/2095951