uname

system informationLinux/Unix
The uname command is one of the most frequently used commands in Linux/Unix-like operating systems. uname Print system information

Quick Reference

Command Name:

uname

Category:

system information

Platform:

Linux/Unix

Basic Usage:

uname [options] [arguments]

Common Use Cases

    Syntax

    uname [OPTION]...

    Options

    Option Description
    -a, --all Print all information
    -s, --kernel-name Print the kernel name (default)
    -n, --nodename Print the network node hostname
    -r, --kernel-release Print the kernel release
    -v, --kernel-version Print the kernel version
    -m, --machine Print the machine hardware name
    -p, --processor Print the processor type (non-portable)
    -i, --hardware-platform Print the hardware platform (non-portable)
    -o, --operating-system Print the operating system
    --help Display help information and exit
    --version Output version information and exit

    Examples

    How to Use These Examples

    The examples below show common ways to use the uname command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    # Print the kernel name uname
    # Print all available information uname -a
    # Print only the kernel version uname -r
    # Print the machine hardware name uname -m
    # Advanced Examples Advanced
    # Print the operating system uname -o # Print the processor type uname -p # Print the kernel name, version, and release uname -srv # Use in a shell script to check system type if [ $(uname) = "Linux" ]; then echo "This is a Linux system" elif [ $(uname) = "Darwin" ]; then echo "This is a macOS system" fi # Check architecture for conditional execution if [ $(uname -m) = "x86_64" ]; then echo "This is a 64-bit system" else echo "This is not a 64-bit system" fi # Format the output for logging echo "System: $(uname -s) $(uname -r) on $(uname -m)" # Get kernel release for compatibility check kernel_version=$(uname -r) if [[ "$kernel_version" > "5.0.0" ]]; then echo "Kernel version is compatible" fi # Save system information to a file uname -a > system_info.txt # Use with other commands in a pipeline uname -a | grep -i linux

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The `uname` command is a fundamental Unix/Linux utility that prints basic system information. Its name is short for "Unix Name," and it's included in the POSIX standard, making it available on virtually all Unix-like operating systems. The command provides a simple way to identify the system you're working on, which is particularly useful in shell scripts that need to adapt to different environments. By default (with no options), `uname` simply prints the kernel name (like "Linux" or "Darwin"). However, its true power comes from the various options that allow you to query specific system information: - **Kernel Information**: The `-s`, `-r`, and `-v` options provide details about the kernel name, release, and version, which can be crucial for compatibility checks or debugging kernel-specific issues. - **Hardware Information**: The `-m`, `-p`, and `-i` options reveal details about the hardware, such as the machine architecture (e.g., "x86_64" or "aarch64") and processor type. This is valuable for installing the correct software binaries or making architecture-specific optimizations. - **Network Information**: The `-n` option shows the system's network node hostname, which can help identify the specific machine in a networked environment. - **Operating System**: The `-o` option identifies the operating system, which might differ from the kernel name (e.g., "GNU/Linux" instead of just "Linux"). The most commonly used option is `-a` (all), which provides a comprehensive overview of the system in a single line. This is often the first command used when troubleshooting an unfamiliar system. It's worth noting that some options (like `-p` and `-i`) are marked as "non-portable" because their output can vary significantly between different Unix implementations, making them less reliable for cross-platform scripts. In practical usage, `uname` serves several important purposes: 1. **System Identification**: It helps administrators and users quickly identify the system they're working on. 2. **Conditional Scripting**: Shell scripts often use `uname` output to make decisions based on the operating system or architecture. 3. **Compatibility Checking**: Software installers may check the kernel version or architecture to ensure compatibility. 4. **Bug Reporting**: When reporting issues, `uname -a` output provides valuable context about the system environment. While `uname` provides basic system information, it's often complemented by more specialized commands like `lscpu`, `dmidecode`, or `cat /proc/cpuinfo` on Linux systems when more detailed hardware information is needed. Nevertheless, it remains one of the most universally available commands for quick system identification across Unix-like operating systems.

    Related Commands

    These commands are frequently used alongside uname or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the uname command works in different scenarios.

    $ uname
    View All Commands