linux - 如何找到某个命令的目录?

我知道,当您在 shell 上时,唯一可以使用的命令是那些可以在 PATH 上设置的某个目录中找到的命令。 即使我不知道如何查看我的 PATH 变量上的目录(这是另一个可以回答的好问题),我想知道的是:

我来shell写:

$ lshw

我想知道 shell 上的一个命令,它可以告诉我这个命令的位置。也就是说,这个“可执行文件”在哪里?

类似:

$ location lshw
/usr/bin

最佳答案

如果您使用的是 Bash 或 zsh,请使用:

type -a lshw

这将显示目标是内置、函数、别名还是外部可执行文件。如果是后者,它将显示它出现在 PATH 中的每个位置。

bash$ type -a lshw
lshw is /usr/bin/lshw
bash$ type -a ls
ls is aliased to `ls --color=auto'
ls is /bin/ls
bash$ zsh
zsh% type -a which
which is a shell builtin
which is /usr/bin/which

在 Bash 中,对于函数 type -a 也会显示函数定义。你可以使用 declare -f functionname 来做同样的事情(你必须对 zsh 使用它,因为 type -a 没有)。

https://stackoverflow.com/questions/2869100/

相关文章:

linux - 如何查看符号链接(symbolic link)的完整绝对路径

linux - 在 tmux 客户端之间移动窗口

python - Python中的异步方法调用?

python - "for line in..."导致 UnicodeDecodeError : '

ruby - 即使在使用 rvm pkg install zlib 后也无法加载此类文件 - zli

python - 如何使用 Python 将整个文件目录复制到现有目录中?

python - 如何将字符串复制到剪贴板?

linux - 如何列出(ls)目录中最后修改的 5 个文件?

linux - 如何在 Linux shell 中对变量进行除法?

python - 名称错误 : name 'reduce' is not defined in Py