& Lt; hash command: Display, add or clear hash tables & gt;

Source: Internet
Author: User
Tags builtin

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

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.