2

The binaries are all but identical:

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  |>.@.....N.@.....|
 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|

This was discovered because of another Q&A which mentioned the similarity in functionality.

Since these are essentially identical, why are there two of them? Why not just use a symlink (especially since one is in /usr/bin)?

l0b0
  • 8,819
  • I wonder how do you found this similarity. By the way, a symlink cannot work, given the required -m option to uname to obtain the same behavior. I would see into coreutils sources. – enzotib Dec 07 '11 at 10:59
  • uname could just check basename "$0" - If it's arch, then act like uname -m. But of course you could create another symlink called uname to that symlink, and you'd be back where you started. – l0b0 Dec 07 '11 at 11:54
  • This is a good point IMO: in bash you could check for the basename, in C (coreutils) for argv[0]. Why it is done differently I don't know (the 'symlink' approach would save some space). – arrange Dec 07 '11 at 12:23

2 Answers2

2

arch is essentially an alias for uname -m, but not done through bash.

It's built using the uname.c and uname-arch.c code, and in the uname-arch.c you only see

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

The uname_mode variable is used in uname.c so that it is able to tell if it was called via uname or arch.

arrange
  • 14,959
1

I'm not too sure but I guess both are included in GNU Core Utils since it's UNIX.

For example if you consider the two programs "who" and "whoami", they essentially do the same thing, ie prints a list of active users. Where "whoami" prints your name and "who" prints your name + the name of other active users.

"Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface." -- Doug McIlroy

Utsav
  • 566
  • uname does many things, as demonstrated by how it's shoehorned into arch. Maybe it should be split into several smaller programs. – l0b0 Dec 07 '11 at 11:58