We can add items to the hash table that can be used again in the shell. We can also print the locations of multiple commands separated by spaces, i.e., Adding a Command Path and Name to the Bash Hash Table We can also print the remembered locations of commands which are used during the session by using the -t option. We can display the hash table for the current session by invoking hash without any argument. Value other than zero refers that the command_name is not found, or an invalid option is given. The hash command returns '0' for success. If multiple command_names are given there, precede each location with corresponding command_nameĮach command_name specified is searched for in the path environment variable, and if found, is added to the list of remembered commands. Print the remembered location of each command_name.
#Hashtab for linux full#
Use pathname as the full path of command_name. Options -dįorget the remembered locations of command_name.ĭisplay the information that can be used again as an input for another program. If there are no arguments, it displays the information about previously used commands and their locations. The syntax above is used to determine and remember the full pathname of each command_name. Without any switches, hash lists the previously used commands, their locations, and the number of times they have been executed during the session. The built-in 'hash' command is responsible for maintaining the hash table. In this case, a full search of the directories in the path is performed to get the command data. However, if the command is moved after recording its location in a table, the shell will not be able to find the command. After that, Bash starts checking the table to find the location of the command instead of looking for the command again. When the Bash gets that command, it keeps the location in a hash table so that it can remember the location of the command. In other words, when any command is executed without naming its path, the shell starts searching for that command within the directories, which are listed in the path variable. It provides a complete pathname of each command name. It keeps the locations of recently executed programs and shows them whenever we want to see it. It is used for views, resets, or manually changes within the bash path hash. On UNIX-like operating systems, a hash is a built-in command of the bash shell, which is used to list a hash table of recently executed commands.