Intro To 'uname' Command In Linux
2023-05-10 - By Robert Elder
I use the 'uname' command as a quick way to see information about my operating system:
uname
and the output is:
Linux
Typically, I run the uname command with the '-a' flag to show all of the system information that this command can provide:
uname -a
and the output is:
Linux robert-ThinkPad-P15v-Gen-1 5.15.0-60-generic #66~20.04.1-Ubuntu SMP Wed Jan 25 09:41:30 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
The uname command supports various flags to show certain fields individually, such as the kernel release version and the hardware platform:
uname --kernel-name
uname --nodename
uname --kernel-release
uname --kernel-version
uname --machine
uname --processor
uname --hardware-platform
uname --operating-system
the output from running all of the commands above is:
Linux
robert-ThinkPad-P15v-Gen-1
5.15.0-60-generic
#66~20.04.1-Ubuntu SMP Wed Jan 25 09:41:30 UTC 2023
x86_64
x86_64
x86_64
GNU/Linux
This ability to print individual fields could be useful for scripting purposes. Here, I have an example of a script called 'do_install.sh' that verifies the hardware platform before attempting to start an install process that only works on the 'x86_64' platform:
#!/bin/bash
if [ "$(uname --machine)" == "x86_64" ]
then
echo "arch was x86_64"
echo "... Run x86_64 install commands..."
else
echo "arch was something else, install cannot continue."
fi
If I try to run the above script on a platform where the machine name is 'x86_64' the output will be the following:
arch was x86_64
... Run x86_64 install commands...
but if the machine name has some other value (such as 'i386'), the output will be the following:
arch was something else, install cannot continue.
And that's why the 'uname' command is my favourite Linux command.
Intro To 'stty' Command In Linux
Published 2023-10-04 |
$1.00 CAD |
Intro To 'nproc' Command In Linux
Published 2023-07-15 |
Intro To 'comm' Command In Linux
Published 2023-09-06 |
How To Force The 'true' Command To Return 'false'
Published 2023-07-09 |
A Surprisingly Common Mistake Involving Wildcards & The Find Command
Published 2020-01-21 |
A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
Published 2019-08-01 |
Intro To 'chroot' Command In Linux
Published 2023-06-23 |
Join My Mailing List Privacy Policy |
Why Bother Subscribing?
|