Hash commands in linux:
Note: There is a hash table in linux. When you start the system, the hash table is empty. Whenever you run a command, the hash table records the path of this command, it is equivalent to cache. The first time you run the shell interpreter, the shell interpreter searches for the PATH of the command from the PATH by default. When you use the command for the second time, the shell interpreter first checks the hash table, without this command, you can search for it in the PATH.
Role of the hash table: greatly increase the invocation speed of commands.
Hash parameters:
[Root @ redhat ~] # Hash // enter hash or hash-l to view the contents of the hash table. It is blank when I start the system.
Hash: hash table empty
[Root @ redhat ~] # Hash-l
Hash: hash table empty
After I run two commands, I can view them again:
[Root @ redhat ~] # The hash // hash table records the number of times the command is executed and the absolute path of the command.
Hits command
1/bin/cat
1/bin/ls
[Root @ redhat ~] # Hash-l // Add the parameter-l to view the path of the hash table command or its name, which may be an alias.
Builtin hash-p/bin/cat
Builtin hash-p/bin/ls
[Root @ redhat ~] # Hash-p/bin/ls bb // Add a hash table. You can see that I re-wrote the ls command and renamed it bb.
[Root @ redhat ~] # Bb // when I run bb, the ls command is executed.
Anaconda-ks.cfg icmp_echo_ignore_aly ~ Pub. key
Dead. letter icmp_echo_ignore_alz ~ Rpmbuild
Icmp_echo_ignore_all ~ Install. log RPM-GPG-KEY-useradd
Icmp_echo_ignore_alw ~ Install. log. syslog RPM-GPG-KEY-westos
Icmp_echo_ignore_alx ~ Passwd
[Root @ redhat ~] # The hash-t ls //-t parameter allows you to view the command path in the hash table. What if the hash table does not exist?
/Bin/ls
[Root @ redhat ~] # Hash-t df // if I have not used df, run the hash command and the system will prompt that the command cannot be found.
-Bash: hash: df: not found
[Root @ redhat ~] # Hash-r // clear the hash table, clear all
[Root @ redhat ~] # Hash-l
Hash: hash table empty
[Root @ redhat ~] # Hash-l
Builtin hash-p/bin/cat
Builtin hash-p/bin/ls
[Root @ redhat ~] # Hash-d cat // clear one of them
[Root @ redhat ~] # Hash-l
Builtin hash-p/bin/ls