Which command prints the kernel version, suitable for scripting?

Prepare for the Red Hat Certified Systems Admin Exam EX200. Enhance your skills with interactive quizzes, flashcards, and detailed explanations. Ace your certification exam today!

Multiple Choice

Which command prints the kernel version, suitable for scripting?

Explanation:
To script the kernel version, you want a clean, stable value. The uname command with the -r option prints just the kernel release, which is exactly what you need for comparisons or conditional logic. It outputs a concise string like 6.2.0-rc7, without extra text, making it reliable for scripts. Other commands pull in extra data or reflect different concepts. uname -a shows all system information, which is not convenient to parse for a version check. cat /proc/version includes the kernel version plus build details like the compiler and build date, adding noise you’d have to trim. rpm -q kernel lists installed kernel packages and may not equal the running kernel, plus it depends on the package manager state rather than the active kernel.

To script the kernel version, you want a clean, stable value. The uname command with the -r option prints just the kernel release, which is exactly what you need for comparisons or conditional logic. It outputs a concise string like 6.2.0-rc7, without extra text, making it reliable for scripts.

Other commands pull in extra data or reflect different concepts. uname -a shows all system information, which is not convenient to parse for a version check. cat /proc/version includes the kernel version plus build details like the compiler and build date, adding noise you’d have to trim. rpm -q kernel lists installed kernel packages and may not equal the running kernel, plus it depends on the package manager state rather than the active kernel.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy