如何查看/ bin / sh指向的内容 [英] How to see what /bin/sh points to
问题描述
我正在阅读/ bin / sh和/ bin / bash之间的区别,并遇到了一个有趣的问题/答案:此处
我对答案做了评论,并在标题中问了同样的问题他回答了一个更新的答案:
如何找出/ bin / sh指向系统的内容?
复杂之处在于/ bin / sh可能是符号链接或硬
链接。如果是符号链接,则可以通过以下便携式方式来解决:
> %文件-h / bin / sh
> / bin / sh:指向bash的符号链接
如果是硬链接,
尝试
> %找到-L / bin -samefile / bin / sh
> / bin / sh
> / bin / bash
我尝试了这个并遇到了麻烦,所以我想我将再提出一个问题。 / p>
链接结果中的结果:
>文件-h / bin / sh
> / bin / sh:可执行文件(RISC System / 6000)或对象模块
>查找-L / bin -samefile / bin / sh
>查找:错误的选项-samefile
我缺少什么?
我正在运行AIX:
> oslevel -s
7100-03-03-1415
如果需要以编程方式测试它们是否相同,您可以使用 stat
查询 / bin / sh $ c中的
inode
$ c>并与 / bin / bash
的 inode
进行比较。
if [$(stat -L -c%i / bin / sh)-eq $(stat -L -c%i / bin / bash)];然后
.....
fi
如果您只需要看一下用相同的眼睛运行 stat
命令,看看它们是否返回相同的 inode
号。
stat -L -c%i / bin / sh
stat -L -c%i / bin / bash
I was reading about the differences between /bin/sh and /bin/bash and came across this interesting question/answer: here
I made a comment to the answer asking this same question in my title to which he replied with an updated answer:
How can you find out what /bin/sh points to on your system?
The complication is that /bin/sh could be a symbolic link or a hard link. If it's a symbolic link, a portable way to resolve it is:
> % file -h /bin/sh
> /bin/sh: symbolic link to bash
If it's a hard link, try
> % find -L /bin -samefile /bin/sh
> /bin/sh
> /bin/bash
I tried this and had trouble so I thought I would make a separate question.
My results from the linked answer:
>file -h /bin/sh
>/bin/sh: executable (RISC System/6000) or object module
>find -L /bin -samefile /bin/sh
>find: bad option -samefile
What am I missing? I'm running AIX:
>oslevel -s
7100-03-03-1415
If you need to programatically test if they are the same, you can use stat
to query the inode
of /bin/sh
and compare with the inode
of /bin/bash
.
if [ $(stat -L -c %i /bin/sh) -eq $(stat -L -c %i /bin/bash) ]; then
.....
fi
If you just need to see with your eyes if they are the same run the stat
commands and see if they return the same inode
number.
stat -L -c %i /bin/sh
stat -L -c %i /bin/bash
这篇关于如何查看/ bin / sh指向的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!