Linuxstar
Published on

hash command-display and clear the hash table queried when the command is running

Jonas

Jonas

1 min read

The hash command is responsible for displaying and clearing the hash table that the system prefers to query when the command is running.

When the hash command is executed without specifying parameters or flags, the hash command reports the contents of the path name list to standard output. This report contains the path name of the command in the current shell environment found by the previous hash command call. It also contains those commands that are called and found by the normal command search process.

Syntax: hash [parameter] [directory]

Common parameters:

-dClear records in the hash table
-lShow commands in hash table
-p<command>Add the command with the full path to the hash table
-rClear the records in the hash table
-tDisplay the full path of the command in the hash table
Example

Display the commands in the hash table:

[root@linuxstar ~]# hash -l 

Delete the command in the hash table:

[root@linuxstar ~]# hash -r 

Add commands to the hash table:

[root@linuxstar ~]# hash -p /usr/sbin/adduser myadduser 

Clear records in the hash table:

[root@linuxstar ~]# hash -d

Display the full path of the command in the hash table:

[root@linuxstar ~]# hash -t