Bird
0
0

You want to write a script that detects if the system is Ubuntu, CentOS, or Fedora by reading /etc/os-release. Which approach is best?

hard📝 Application Q8 of 15
Linux CLI - Linux Basics and Terminal
You want to write a script that detects if the system is Ubuntu, CentOS, or Fedora by reading /etc/os-release. Which approach is best?
ALook for the presence of /etc/centos-release file
BCheck the value of the ID field in /etc/os-release
CCheck the kernel version with uname -r
DRun 'lsb_release -a' and parse Distributor ID
Step-by-Step Solution
Solution:
  1. Step 1: Understand /etc/os-release usage

    This file contains a standard ID field identifying the distribution.
  2. Step 2: Compare other methods

    Kernel version doesn't identify distro, /etc/centos-release only for CentOS, lsb_release may not be installed.
  3. Final Answer:

    Check the value of the ID field in /etc/os-release -> Option B
  4. Quick Check:

    Use ID field in os-release for distro detection [OK]
Quick Trick: ID field in /etc/os-release reliably identifies distro [OK]
Common Mistakes:
  • Using kernel version for distro
  • Relying on distro-specific files
  • Assuming lsb_release always available

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes