uname
uname is related to hostname but more flexible. On x86 architecture, it is less informative than on vendor-designed hardware; the SunFire E25k reports itself through uname -i as SUNW,Enterprise-25000, and the T5240 reports SUNW,T5240. By itself, uname reports the basic name of the running kernel, such as Linux or SunOS or FreeBSD. With other switches, it reports on the hostname (-n), kernel release (-r) and version (-v), CPU architecture (-m), operating system (-o), processor (-i), and hardware platform (-i). These are combined with the -a switch, which is normally equivalent to uname -snrvmpio.
uname is a useful way for a script to tailor itself to the platform it finds itself running on. This snippet determines the capability of the CPU and reports back accordingly. The dirname section earlier in this chapter also used uname to determine which OS it is running on, and makes a (rather broad) assumption about which package management system to use.
$ cat uname.sh
#!/bin/sh
case 'uname -m' in
amd64|x86_64) bits=64 ;;
i386|i586|i686) bits=32 ;;
*) bits=unknown ;;
esac
echo "You have a ${bits}-bit machine."
uname.sh
$ ./uname.sh
You have a 64-bit machine.
$
It is useful to know what to expect from uname, so Table 14-1 presents a few samples from different operating systems and architectures. The first three in the table are different flavors ...