[one-liner]: Using the Command lsb_release to Determine Linux Distro Version Info

Background

If you need to determine which version of Linux you’re using you can use the command lsb_release. It’s part of the Linux Standards Base which is a specification that was created by the Linux Foundation.

Solution

Obviously there are other ways to do this, for example, on a Redhat based system you can look for the file /etc/redhat-release, for example:

1
2
# /etc/redhat-release
Fedora release 14 (Laughlin)

But a more consistent way to do this across any Linux Distros that purport to be following the LSB spec, you can also use the command lsb_release. lsb_release takes a couple of command line switches, here are a few of the more common ones in use on my Fedora 14 system:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
## bare, no switches
% lsb_release 
LSB Version::core-4.0-amd64:core-4.0-ia32:core-4.0-noarch
 
## display release info
% lsb_release -r
Release:14
 
## display release info + description
% lsb_release -rd
Description:Fedora release 14 (Laughlin)
Release:14
 
## display release info, description, and the distro's codename
% lsb_release -rdc
Description:Fedora release 14 (Laughlin)
Release:14
Codename:Laughlin
 
## display everything
% lsb_release -a
LSB Version::core-4.0-amd64:core-4.0-ia32:core-4.0-noarch
Distributor ID:Fedora
Description:Fedora release 14 (Laughlin)
Release:14
Codename:Laughlin

Here’s the same switches on my Ubuntu 10.10 system:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
% lsb_release
No LSB modules are available.
 
% lsb_release -r
Release:10.10
 
% lsb_release -rd
Description:Ubuntu 10.10
Release:10.10
 
% lsb_release -rdc
Description:Ubuntu 10.10
Release:10.10
Codename:maverick
 
% lsb_release -a
No LSB modules are available.
Distributor ID:Ubuntu
Description:Ubuntu 10.10
Release:10.10
Codename:maverick

…and here they are on my Ubuntu 11.04 system:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
% lsb_release 
No LSB modules are available.
 
% lsb_release -r
Release:11.04
 
% lsb_release -rd
Description:Ubuntu 11.04
Release:11.04
 
% lsb_release -rdc
Description:Ubuntu 11.04
Release:11.04
Codename:natty
 
% lsb_release -a
No LSB modules are available.
Distributor ID:Ubuntu
Description:Ubuntu 11.04
Release:11.04
Codename:natty

Lsb_release is a nice improvement if you need to write scripts or installation scripts for a variety of Linux Distros.

References

NOTE: For further details regarding my one-liner blog posts, check out my one-liner style guide primer.

This entry was posted in linux, LSB, one-liner, Syndicated, sysadmin, tips & tricks. Bookmark the permalink.

Comments are closed.