0

The "command hashing system" should store the path of the shell commands somewhere, right ? Is it a database or what? I am wondering where that is. Also, Is it encrypted ?

Do we have a way of knowing where and how the hashing system stores those commands?

I appreciate your suggestions. Thanks

Paulo Tomé
  • 3,782
David
  • 309
  • 2
    The information is cached in memory. See https://unix.stackexchange.com/questions/86012/what-is-the-purpose-of-the-hash-command. – Paulo Tomé Mar 26 '20 at 00:27
  • 2
    That's just a feature of your shell, not of the system. The hashed commands aren't "stored" on any non-volatile medium, nor are they encrypted (why should they be). On a more practical note, you can access the command hash table in bash via either the hash builtin or the BASH_CMDS associative array. –  Mar 26 '20 at 00:35
  • Thanks @mosvy. The reason I asked about whether it's encrypted or not is that if you could somehow change the path of a highly used command, you could make a security hole and run a '"dangerous" script instead. (Not that I want to hack or something; I was just curious) – David Mar 26 '20 at 00:50
  • 1
    That would be a very roundabout way to do it. But if you want & as I told you: BASH_CMDS[ls]=/bin/yes. Then use ls. hash -r to let bash forget about it. –  Mar 26 '20 at 00:55
  • @mosvy Wow thanks. That's exactly what I was looking for. – David Mar 26 '20 at 00:58
  • @mosvy But looks like it doesn't work that way. When you change the path, ls disappears from the hash table. Did it work for you? – David Mar 26 '20 at 01:06
  • @mosvy It works. Never mind. Thanks again – David Mar 26 '20 at 01:15
  • Yes, if you change the PATH, the hash table will be cleared. That's standard behaviour. –  Mar 26 '20 at 01:16
  • @mosvy No, actually it works. I had a small problem with ls because it was aliased and its arguments were used for the substitute command. I tried some other command, and it worked. (I am using Arch. Not all distros show the same behaviour tho) – David Mar 26 '20 at 01:19

0 Answers0