uname -m 与 arch

uname -m 与 arch

二进制文件几乎完全相同:

diff -u <(hexdump -C /bin/uname) <(hexdump -C /usr/bin/arch)
--- /dev/fd/63  2011-12-07 11:38:18.344027319 +0100
+++ /dev/fd/62  2011-12-07 11:38:18.344027319 +0100
@@ -38,8 +38,8 @@
 00000250  6f 2e 32 00 04 00 00 00  10 00 00 00 01 00 00 00  |o.2.............|
 00000260  47 4e 55 00 00 00 00 00  02 00 00 00 06 00 00 00  |GNU.............|
 00000270  0f 00 00 00 04 00 00 00  14 00 00 00 03 00 00 00  |................|
-00000280  47 4e 55 00 7a 96 5e a8  ad 05 ae 51 d7 26 8a fa  |GNU.z.^....Q.&..|
-00000290  bd 1a a6 ca 5a b3 02 dc  25 00 00 00 2a 00 00 00  |....Z...%...*...|
+00000280  47 4e 55 00 fd 70 a8 c1  df cc 73 cb 78 c6 a5 77  |GNU..p....s.x..w|
+00000290  04 d1 36 af 91 e8 3f 7d  25 00 00 00 2a 00 00 00  |..6...?}%...*...|
 000002a0  18 00 00 00 19 00 00 00  22 00 00 00 00 00 00 00  |........".......|
 000002b0  14 00 00 00 00 00 00 00  1b 00 00 00 00 00 00 00  |................|
 000002c0  26 00 00 00 28 00 00 00  0a 00 00 00 00 00 00 00  |&...(...........|
@@ -1315,10 +1315,10 @@
 000060f0  3e 10 40 00 00 00 00 00  4e 10 40 00 00 00 00 00  |>[email protected].@.....|
 00006100  5e 10 40 00 00 00 00 00  00 00 00 00 00 00 00 00  |^.@.............|
 00006110  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
-00006120  01 00 00 00 00 00 00 00  00 41 40 00 00 00 00 00  |.........A@.....|
+00006120  02 00 00 00 00 00 00 00  00 41 40 00 00 00 00 00  |.........A@.....|
 00006130  40 61 60 00 00 00 00 00  01 00 00 00 00 00 00 00  |@a`.............|
 00006140  00 01 00 00 00 00 00 00  20 62 60 00 00 00 00 00  |........ b`.....|
-00006150  01 00 00 00 75 6e 61 6d  65 00 00 00 79 ac e0 1f  |....uname...y...|
+00006150  01 00 00 00 61 72 63 68  00 00 00 00 d2 34 36 6a  |....arch.....46j|
 00006160  00 2e 73 68 73 74 72 74  61 62 00 2e 69 6e 74 65  |..shstrtab..inte|
 00006170  72 70 00 2e 6e 6f 74 65  2e 41 42 49 2d 74 61 67  |rp..note.ABI-tag|
 00006180  00 2e 6e 6f 74 65 2e 67  6e 75 2e 62 75 69 6c 64  |..note.gnu.build|

这是因为另一个问答其中提到了功能上的相似性。

既然它们本质上是相同的,为什么会有两个呢?为什么不直接使用符号链接(尤其是因为其中一个在 /usr/bin 中)?

答案1

arch本质上是 的别名uname -m,但不是通过 bash 完成的。

它是使用uname.cuname-arch.c代码构建的,并且在uname-arch.c你只看到

#include "uname.h"
int uname_mode = UNAME_ARCH;

使用该uname_mode变量是uname.c为了能够判断它是通过uname或调用的arch

答案2

我不太确定,但我猜两者都包含在 GNU Core Utils 中,因为它是 UNIX。

例如,如果您考虑两个程序“who”和“whoami”,它们本质上做同样的事情,即打印活动用户列表。其中“whoami”打印您的姓名,“who”打印您的姓名+其他活动用户的名称。

“编写只做一件事的程序,并把它做好。编写程序以协同工作。编写程序来处理文本流,因为这是一个通用接口。”——Doug McIlroy

相关内容