134

Often times I will ssh into a new client's box to make changes to their website configuration without knowing much about the server configuration. I have seen a few ways to get information about the system you're using, but are there some standard commands to tell me what version of Unix/Linux I'm on and basic system information (like if it is a 64-bit system or not), and that sort of thing?

Basically, if you just logged into a box and didn't know anything about it, what things would you check out and what commands would you use to do it?

cwd
  • 45,389

13 Answers13

115

If I need to know what it is say Linux/Unix , 32/64 bit

uname -a 

This would give me almost all information that I need,

If I further need to know what release it is say (Centos 5.4, or 5.5 or 5.6) on a Linux box I would further check the file /etc/issue to see its release info ( or for Debian / Ubuntu /etc/lsb-release )

Alternative way is to use the lsb_release utility:

lsb_release -a

Or do a rpm -qa | grep centos-release or redhat-release for RHEL derived systems

cwd
  • 45,389
Gaumire
  • 1,311
  • 4
    In 2016 it does not seem like lsb_release works any longer with modern distros. I tested the command on Amazon Linux AMI release 2016.03 and CentOS Linux 7 and it was not found. It seems like ls cat /etc/os-release is the best solution currently with uname -a somewhat usable if a bit opaque (e.g. Amazon Linux AMI release 2016.03 vs. Linux ip-x-x-x-x 4.4.11-23.53.amzn1.x86_64 #1 SMP Wed Jun 1 22:22:50 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux) – runamok Sep 19 '16 at 19:00
  • Well Done (y) :) – Sam Jun 09 '17 at 12:10
  • For me uname -a says 20.04.1 while lsb_release -a and cat /etc/os-release say 20.04.6. And software-updater wants to update to 20.04.2. What's going on there? – Joooeey Jul 27 '23 at 11:24
66

Use the following commands to get more details:

  1. cat /etc/*release*
  2. uname -a
Erathiel
  • 1,575
Alapati
  • 761
  • 5
    i like this answer better than the accepted one – Randy L Sep 22 '17 at 17:08
  • 1
    Add cat /proc/version and it covers every release I've found over the years. I've never seen a case where /proc/version wasn't helpful, but I've seen cases where one or both of the above don't help (can't remember which but most likely embedded systems.) – Jeff Learman Feb 25 '20 at 15:13
9

There are a ton of answers but I'm looking for more generic. AFAI am concerned the following works on most of systems.

cat /etc/os-release

Example output:

sh-4.4$ cat /etc/os-release                                                                                                                                                                           
NAME=Fedora                                                                                                                                                                                           
VERSION="26 (Twenty Six)"                                                                                                                                                                             
ID=fedora                                                                                                                                                                                             
VERSION_ID=26                                                                                                                                                                                         
PRETTY_NAME="Fedora 26 (Twenty Six)"                                                                                                                                                                  
ANSI_COLOR="0;34"                                                                                                                                                                                     
CPE_NAME="cpe:/o:fedoraproject:fedora:26"                                                                                                                                                             
HOME_URL="https://fedoraproject.org/"                                                                                                                                                                 
BUG_REPORT_URL="https://bugzilla.redhat.com/"                                                                                                                                                         
REDHAT_BUGZILLA_PRODUCT="Fedora"                                                                                                                                                                      
REDHAT_BUGZILLA_PRODUCT_VERSION=26                                                                                                                                                                    
REDHAT_SUPPORT_PRODUCT="Fedora"                                                                                                                                                                       
REDHAT_SUPPORT_PRODUCT_VERSION=26                                                                                                                                                                     
PRIVACY_POLICY_URL=https://fedoraproject.org/wiki/Legal:PrivacyPolicy                                                                                                                                 
  • 3
    This will work on Linux distros that use systemd. For older versions of those distros that don't use systemd, this won't work (e.g. RHEL 6), and for distros that don't use systemd at all this won't work. The second most voted answer will cat this file anyway, so there's no reason not to prefer that more general command. – Wildcard Aug 19 '19 at 23:48
6

Use cat /proc/version

Result:

Linux version 3.14.27-100.fc19.x86_64 (mockbuild@bkernel02.phx2.fedoraproject.org) (gcc version 4.8.3 20140911 (Red Hat 4.8.3-7) (GCC) ) #1 SMP Wed Dec 17 19:36:34 UTC 2014

I believe this works for most distros, and provides a more concise answer than cat /etc/*release* and more complete answer than uname -a. However, use of /proc for things other than processes is now eschewed, so maybe it'll disappear someday.

Eje
  • 129
  • 1
    This worked for me – tinonetic Apr 01 '18 at 19:50
  • 2
    On Apline 3.10.4 this returned something unexpected: Linux version 4.19.76-linuxkit (root@d203b39a3d78) (gcc version 8.3.0 (Alpine 8.3.0)) #1 SMP Thu Oct 17 19:31:58 UTC 2019 – b01 Feb 24 '20 at 12:24
  • @b01 Thanks for the input. At least it got the Alpine part correct. ;-) Where did 3.10.4 come from, uname -a? It's sad that there is no single correct answer! – Jeff Learman Feb 25 '20 at 15:08
  • I learned this while writing a tool that did a survey of connected systems which were embedded Linux running on various brands and models of storage servers. It was the only command I found that returned something useful in every case, and since then I've never seen it not be useful, even on BusyBox-based distros. – Jeff Learman Feb 25 '20 at 15:20
  • 1
    @JeffLearman I was using a Go Lang Alpine Docker image of 1.13-alpine-3.10 and wanted to know the bug release number. I ended up trying quite a few of these answers to see which worked and not. – b01 Feb 26 '20 at 18:50
  • /proc/version tells the kernel version, including the compiler used to compile it. While the distribution name may appear in the compiler version (as in all examples here), it's hard to turn that into the release version of the distribution if that's what one wants. (And while the question doesn't exactly say that, a lot of the answers and comments here seem to assume that's at least part of what is meant.) The kernel version can be determined with uname, which also has the upside that it works on other systems too, not just Linux. – ilkkachu Oct 13 '21 at 20:40
  • @ilkkachu - Unfortunately, uname -a returned unhelpful information on many embedded systems. It's the first thing I tried, and probably is the best thing to try first. But thanks for pointing out that /proc/version can be misleading. – Jeff Learman Oct 14 '21 at 17:10
5

You should look into the uname command.

I have to deal with a large parc of heterogenous machines. uname -a is usually my first reflex when I log in.

rahmu
  • 20,023
5

To combine some ideas here:

cat /etc/*_version /etc/*-release && uname -a

Should get you want you need on any distribution.

Adam Grant
  • 150
  • 1
  • 3
  • To those who are searching for which version is alpine running inside docker, this command works and produces following output:
    3.14.2
    NAME="Alpine Linux"
    ID=alpine
    VERSION_ID=3.14.2
    PRETTY_NAME="Alpine Linux v3.14"
    HOME_URL="https://alpinelinux.org/"
    BUG_REPORT_URL="https://bugs.alpinelinux.org/"```
    
    – Suraj Dubey Oct 24 '21 at 13:10
4

Type in the command line:

uname -a

That'll give you all the information you seek.

Try also:

man uname to restrict the information

4

For the Alpine distribution:

cat /etc/alpine-release
3.5.2
mkobit
  • 149
  • 1
  • 3
3

inxi is a System Information Tool for Linux. It displays handy information concerning system hardware (hard disk, sound cards, graphic card, network cards, CPU, RAM, and more), together with system information about drivers, Xorg, desktop environment, kernel, GCC version(s), processes, uptime, memory, and a wide array of other useful information.

If inxi is not installed in your system, you can install it by:

$ sudo apt install inxi       [On Debian/Ubuntu/Linux Mint]
$ sudo yum install inxi       [On CentOs/RHEL/Fedora]
$ sudo dnf install inxi       [On Fedora 22+]

In manpage you can fine that -S option can be used to get host name, kernel, desktop environment (if in X/Wayland), distro.

% inxi -S
System:    Host: blueray-i5 Kernel: 5.4.0-53-generic x86_64 bits: 64 Desktop: Cinnamon 4.6.7 Distro: Linux Mint 20 Ulyana

This can be used as a debugging, and/or forum technical support tool. So you might consider keeping it in your toolbelt.

Ahmad Ismail
  • 2,678
1

Centos 5 using file in /etc/redhat-release

Anthon
  • 79,293
Kurdt94
  • 29
1

whatami by Remy Evard at Argonne National Lab. Install and run using these commands:

$ wget https://raw.githubusercontent.com/open-mpi/mtt/master/client/whatami/whatami && chmod a+x whatami
Resolving raw.githubusercontent.com... 151.101.116.133
Connecting to raw.githubusercontent.com|151.101.116.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 24434 (24K) [text/plain]
Saving to: 'whatami'

whatami                                           100%[============================================================================================================>]  23.86K  --.-KB/s    in 0.02s   

2018-08-15 18:54:42 (1.49 MB/s) - 'whatami' saved [24434/24434]

$ ./whatami
darwin-macosx_10.11-x86_64
emallove
  • 148
  • 1
    You might want to link to that tool or explain how you installed it, it's not on by default. – slm Aug 14 '18 at 16:12
1

A problem I found with the practical uname-a is that, in microsoft's wsl, it always returns something like (even inside docker containers!):

Linux d0b341b1f694 5.10.16.3-microsoft-standard-WSL2 #1 SMP Fri Apr 2 22:23:49 UTC 2021 x86_64 Linux

On the other hand, when using cat /etc/os-release (or cat /etc/*release*), also in wsl, it returns the correct system of the container (or of the linux distro).

-1

For CentOs

$ cat /etc/centos-release
SHMZ release 6.6 (Final)