bash - 使用 'hash' 命令

标签 bash hash ffmpeg

我正在开发一个基于 ffmpeg 的小应用程序,并且我阅读了 tutorial made for ubuntu他们建议在生成的可执行文件上使用命令 hash

我很好奇那个命令,你用过吗?为了什么目的?

当我在我的源文件夹中运行它时,我得到这个(一旦编译)

$ hash
hits    command
   1    /usr/bin/strip
   1    /usr/local/bin/ffmpeg
   1    /usr/bin/svn
   4    /usr/local/bin/brew
   2    /usr/bin/git
   1    /bin/rm
   1    /bin/cat
   1    /usr/bin/ld
   1    /bin/sh
   4    /usr/bin/man
   5    /usr/bin/make
   4    /usr/bin/otool
  15    /bin/ls
   6    /usr/bin/open
   2    /usr/bin/clear

看起来像是我的 bash_history 的总结......

当我在可执行文件上运行它时,我没有显示很多行,而且该应用程序似乎没有任何变化?

$ md5 ffserver
MD5 (ffserver) = 2beac612e5efd6ee4a827ae0893ee338
$ hash ffserver
$ md5 ffserver
MD5 (ffserver) = 2beac612e5efd6ee4a827ae0893ee338

当我寻找 man 时,它只是说这是一个内置函数。真的很有用:)

它在 Linux 和 MacOSX 上确实有效(假设存在) .

最佳答案

hash 实际上不是您的历史;它是一个内置的 bash(1) shell,用于维护最近执行的程序的哈希表:

Bash uses a hash table to remember the full pathnames of executable files (see hash under SHELL BUILTIN COMMANDS below). A full search of the directories in PATH is performed only if the command is not found in the hash table.

(来自 bash(1) .)

您找到的指南可能建议运行它只是为了查看哪个 ffmpeg 命令将在下一步执行;也许分发包提供了一个 ffmpeg 程序,他们想确保如果你只输入 ffmpeg 就会执行新程序而不是发行版提供的程序在外壳上。

这似乎有些牵强,因为它需要在PATH之前包含新ffmpeg 的目录em> 发行版提供的版本,对此无法保证。

关于bash - 使用 'hash' 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5987448/

相关文章:

c++ - ffmpeg 创建 RTP 流

c++ - 每次重新编译后exe校验和不同

php - 如何找出你的机器上 crypt() 使用的算法?

docker - 从docker文件-'pkgs dont match the hashes from req file'安装时哈希值不匹配

linux - FFSERVER 流式传输到任何网络

string - 需要在一定数量的字符后拆分 bash 中的字符串

bash - 显式触发 ERR 陷阱,bash

bash - 通过 grep 管道尾部时没有输出

regex - Bash 补全不适用于 MSYS bash。正则表达式语法错误

ffmpeg - ffmpeg过滤器表达式调用了什​​么随机函数?