Skip to content

Find distro name in lowercase by different tools

Practical and portable shell examples demonstrating multiple reliable methods to extract the Linux distribution identifier (ID) from /etc/os-release using standard Unix tools such as grep, sed, awk, and Perl


Using grep to find distro name

grep '^ID=' /etc/os-release | cut -d= -f2 | tr -d "\"'" | tr 'A-Z' 'a-z'

Using awk to find distro name

awk -F= '$1=="ID"{gsub(/["'\'']/, "", $2); print tolower($2)}' /etc/os-release

Using sed to find distro name

sed -n "s/^ID=['\"]\(.*\)['\"]/\\L\1/p" /etc/os-release

Using sed script to find distro name

sed -n '/^ID=/{
  s/^ID=//
  s/["'\'']//g
  s/.*/\L&/
  p
}' /etc/os-release

Using awk to find distro name (Posix Safe)

awk -F= '$1=="ID"{gsub(/["'\'']/, "", $2); print $2}' /etc/os-release | tr 'A-Z' 'a-z'

Using perl to find distro name

perl -ne 'print lc($1)."\n" if /^ID=['\''"]?([^'\''"]+)['\''"]?$/' /etc/os-release

Using grep to find distro name

grep '^ID=' /etc/os-release | sed 's/^ID=//; s/'\''//g; s/"//g' | tr 'A-Z' 'a-z'

Using echo to find distro name (most simple)

. /etc/os-release
echo "$ID"