UNIX:“wc”的物理位置命令。它不是“/bin”。
这已经是树桩了。我用 C 语言编写了一个 shell 程序,允许用户执行多个命令。根据我迄今为止的研究,所有命令(例如“ls”和“cat”)都位于“/bin/”中。
“wc”未在此目录“/bin”中列出。如果我启动终端,我可以输入“wc fileName”并且它可以工作。我从“/”目录运行“find .wc”,仍然找不到“wc”命令。
有谁知道“wc”藏在哪里?
This has be stump. I wrote a shell program in C that allows the user to execute several commands. Based on my research so far, all the commands such as "ls" and "cat" are located in "/bin/".
The "wc" is not listed in this directory - "/bin". If I fire up a terminal, I can type "wc fileName" and it works. I ran "find . wc" from the "/" directory, and I still can't find the "wc" command.
Does anyone know where "wc" is hiding?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试在 shell 中输入
which wc
...这应该会告诉您它在哪里。在我的机器上,它位于
/bin/
中。但是,如果您只想自行完成路径解析,则可以使用
system()
函数(有关更多信息,请参阅man 3 system
)。正如您在文档中所读到的,这实际上与调用 Bourne shell(或该符号链接指向的任何地方)进行路径解析相同,因此,如果您不希望产生这种开销,那么您将需要坚持使用任何方法您当前正在使用。Try typing
which wc
into your shell...that should tell you where it is.On my machine it is in
/bin/
.However, if you just want the path resolution to be done on it's own, you can use the
system()
function (seeman 3 system
for more information). As you can read in the documentation, that's really the same as invoking the Bourne shell (or wherever the symlink for that points to) for the path resolution, so if you don't want that overhead, you will want to stick with whatever method you are currently using.我尝试了
whereis wc
并在/usr/bin/wc
中找到它I tried
whereis wc
and I get it in/usr/bin/wc
如果您不想担心各个实用程序在哪里,但确实想避免调用
system
所涉及的开销,那么您应该尝试使用中层函数execvp
,或其朋友之一(也列在该页面上)。遗憾的是,没有execvpe
。If you don't want to worry about where individual utilities are, but you do want to avoid the overhead involved in calling
system
, then you should try the middle-level functionexecvp
, or one of its friends (also listed on that page). Sadly, there is noexecvpe
.您可以尝试使用
whence
、which
或whereis
来查找 exec 路径中的任何程序,具体取决于您使用的 shell。像
wc
这样的实用程序通常位于/bin
或/usr/bin
中,或者像/usr/local/bin< /code> 或
/usr/site/bin
。You can try
whence
,which
, orwhereis
to find any program in your exec path, depending on which shell you're using.Utilities like
wc
are usually located in/bin
or/usr/bin
, or in places like/usr/local/bin
or/usr/site/bin
.