How to know which Linux Distribution I'm using? [closed] - linux

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 13 years ago.
Improve this question
Moved to https://superuser.com/questions/80251/how-to-know-which-linux-distribution-im-using
How to know which Linux Distribution I'm using?
uname -a gives
Linux xxxxxx.net 2.6.9-42.0.3.EL.wh1smp #1 SMP Fri Aug 14 15:48:17 MDT 2009 i686 i686 i386 GNU/Linux
How can I know this is Ubuntu/Debian/Fedora or Redhat?
I uses /etc/init.d/serviced restart for restarting serevices, seems it is not Redhat family
Update:
[~]$ cat /etc/issue
cat: /etc/issue: No such file or directory
[~]$ cat /etc/issue.net
cat: /etc/issue.net: No such file or directory
[~]$ lsb_release -a
-sh: lsb_release: command not found
[~]$ cat /etc/*-release
cat: /etc/*-release: No such file or directory
[~]$ cat /etc/*-version
cat: /etc/*-version: No such file or directory
[~]$ cat /etc/*release
cat: /etc/*release: No such file or directory
[~]$ cat /etc/*_release
cat: /etc/*_release: No such file or directory
[~]$ cat /etc/*version
cat: /etc/*version: No such file or directory
[~]$

Try this:
cat /etc/*-release
You could also try /etc/*-version

If you have lsb_release command,
lsb_release -a
will tell you (or just use lsb_release -i).
lsb_release is in Linux Standard Base Core Specification.
Edit: Looks like you're on a Red Hat system. A google search on your uname output suggests so. This is not programmatic, of course!

/etc/issue or /etc/issue.net give a good clue. Newer distros provide /etc/lsb-release which make it easier to determine exact strings progmatically, i.e. distro name / major & minor release / web site, etc.
In the absence of /etc/lsb-release, its much more difficult, hence the creation of lsb-release.
As Alok said, it looks like you are on a rather ancient (or extremely sparse) system. I don't think this is a case that you can (reliably) progmatically determine with a few lines of code.
If all else fails, check to see what kind of package manager is in use (apt / rpm / others), check to see if /etc/init.d is a symlink (rpm / RH distros) or a directory (debian based distros) .. and you have a pretty good clue as to what you can expect to be present in the root file system as far as structure.
You can't please everyone :)

Seems like here's some info:
> cat /etc/issue
Welcome to SUSE LINUX Enterprise Server 9 (i586) - Kernel \r (\l).
> uname -a
Linux boxname 2.6.5-7.244-smp #1 SMP Mon Dec 12 18:32:25 UTC 2005 i686 athlon i386 GNU/Linux
> cat /etc/*-release
SUSE LINUX Enterprise Server 9 (i586)
VERSION = 9
PATCHLEVEL = 3

A list the release filenames for the most common distros:
Release files
And a function that might help you:
Shell script

EL stands for Enterprise Linux in this case, so I think RedHat or a clone (like CentOS). I don't know a good way to programatically find out what distro you're on; there's a few different clues for each one.
cat /etc/redhat_release
cat /etc/debian_version
is a good start. (Note the Ubuntu doesn't modify /etc/debian_version when they pull changes from Debian, so my Ubuntu Karmic system has squeeze/sid in debian_version.)
Edit: forgot about lsb. Good call, Tim Post and Alok. The whole point of LSB is to give distro-independent ways to do things.

Related

How to set vim PATH?

The server manager told me they updated/built vim to the latest version at /opt/vim/src/vim but when I open $vim, it is still the old version. Then I check:
$which vim
/usr/bin/vim
My question is how to set or change $PATH so that I will initiate the latest vim version?
Here is the OS information:
~$ uname -a
Linux ccis4301 3.13.0-88-generic #135-Ubuntu SMP Wed Jun 8 21:10:42 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
~$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.5 LTS"
In your .bashrc or .zshrc set:
export PATH="/opt/vim/src:$PATH"
PATH holds the lists of dirs which are searched for binaries in order one by one. Hence, the order is important.
export PATH=$PATH:/opt/vim/src
will result in picking /usr/bin/vim.
We can override this by flipping the order
export PATH=/opt/vim/src:$PATH
and to make it permanent. Add this to your rc file like ~/.bashrc
echo 'export PATH=/opt/vim/src:$PATH' >> ~/.bashrc
source ~/.bashrc

Bash: No such file or directory?

I try to use an executable script (wkhtmltopdf) on a Linux shared webserver (Debian, 64bit). I am pretty sure that I compiled everything correct, but whenever I want to execute the file I get as an response :
> ./wkhtmltopdf -H
-bash: ./wkhtmltopdf: No such file or directory
To be sure that the file is there, here the ls output :
> ls
wkhtmltoimage wkhtmltopdf
Furthermore I tested the file command on it, which outputs the following :
> file wkhtmltopdf
wkhtmltopdf: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
My question is now :
Why does bash tells me that there is no 'file or directory', when there obviously is one?
My first guess would be that the shared server does not allow to execute binary files? But shouldn't it then be a problem of permissions, with a different bash output?
Edit :
> id
uid=2725674(p8907906) gid=600(ftpusers) groups=600(ftpusers)
> ls -l wkhtmltopdf
-rwxrwxrwx 1 p8907906 ftpusers 39745960 Jan 20 09:33 wkhtmltopdf
> ls -ld
drwx---r-x 2 p8907906 ftpusers 44 Jan 28 21:02 .
I bet you miss dynamic linker. Just do a
readelf --all ./wkhtmltopdf | grep interpreter
You should get an output like this:
[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
There are high chances that you system lacks the interpreter (/lib64/ld-linux-x86-64.so.2 in the example). In this case bash would yell No such file or directory, just like when the binary itself is missing.
You can try to use a different linker. Sometime you can succeed. Just do a:
/path/to/the/linker /path/to/your/executable
This command:
find /lib* -name ld-linux\*
will help you find the linkers on your system. Or you can do the readelf command on some command that does run. It will show you correct, working linker.
OR, since you are running Debian system, just do a
sudo apt-get install wkhtmltopdf
to install native version of the tool :)
In my case
$ readelf --all ./wkhtmltopdf | grep interpreter # readelf: Displays information about ELF files.
[Requesting program interpreter: /lib/ld-linux.so.2]
On a machine where the executable was working:
$ ls -lah /lib/ld-linux.so.2
lrwxrwxrwx 1 root root 25 Apr 16 2018 /lib/ld-linux.so.2 -> i386-linux-gnu/ld-2.27.so
$ dpkg -S /lib/ld-linux.so.2 # -S, --search filename-search-pattern: Search for a filename from installed packages.
libc6:i386: /lib/ld-linux.so.2
So to fix the problem (reference)
sudo dpkg --add-architecture i386
sudo apt update
sudo apt install libc6:i386 # GNU C Library: Shared libraries (from apt show)
Missing the linker was my case as well. I could fix it with the help of nsilent22 answer like this:
readelf --all /usr/local/myprogram | grep interpreter
[Requesting program interpreter: /lib64/ld-lsb-x86-64.so.3]
But that linker did not exist anymore.
The old situation in /lib64 was:
ld-linux-x86-64.so.2 -> /lib/x86_64-linux-gnu/ld-2.31.so
ld-linux-x86-64.so.3 -> ld-linux-x86-64.so.2
So it turned out this was just a symlink to the systems' linker.
Moving over to /lib64 , which itself is a symlink to usr/lib64 and creating a symlink over there did not work. I assume that there are to many symbolic link levels after Debian moved everything into /usr
However creating a 'direct' symlink
ln -s /usr/lib64/ld-linux-x86-64.so.2 /lib64/ld-lsb-x86-64.so.3
did the job; /usr/lib64 now shows:
ld-linux-x86-64.so.2 -> /lib/x86_64-linux-gnu/ld-2.31.so
ld-lsb-x86-64.so.3 -> /usr/lib64/ld-linux-x86-64.so.2
I ran into this issue on my raspberry pi 4 running aarch64 alpine 3.13. Using the answer provided by #vkersten, I was able to determine that I was missing /lib/ld-linux-aarch64.so.1.
I resolved this by installing gcompat with apk add gcompat.

How do I identify the particular Linux flavor via command line?

I'd like to be able to detect which particular Linux flavor is installed on a computer, e.g. Ubuntu vs Fedora, via a command line command.
Some people recommend uname -a, but that only reports the kernel version.
Try the below command....
It worked for me...
cat /proc/version
Once you know that you are running Red Hat for example, you can get to the point with:
cat /etc/redhat-release
Or on Debian:
cat /etc/debian_version
or in general :
cat /etc/*-release
Also you could use the following command
cat /etc/issue
For displaying details including release and codename of the distro
lsb_release -a
You can try:
echo $(lsb_release -si)
Try hostnamectl. It lists the operating system, CPE OS Name, Kernel, Architecture, etc.

Best way to get machine id on Linux?

What is the best-practiced way to get an unique machine ID in GNU/Linux for i386 architecture?
Are there any good ways except the mac address?
Depending on your kernel, the DMI information may be available via sysfs.
Try those:
# cat /sys/class/dmi/id/board_serial
xxxxxxxxxxxxxxx
# cat /sys/class/dmi/id/product_uuid
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
or using a tool
# dmidecode -s baseboard-serial-number
...
# dmidecode -s system-uuid
...
On modern machines with systemd: machine id is created by systemd-machine-id-setup. The location of machine id is documented - in freedesktop machine-id and man machine-id and machine id has a more standardized format - see RFC4122. Just:
cat /etc/machine-id
You can use lshal. This needs hal (apt-get install hal or yum install hal) to be installed first. This way you can access all the info of dmidecode without root permissions.
A non-root equivalent of
# dmidecode | grep -i uuid
will be
$ lshal |grep -i system.hardware.uuid
And similarly other info as per your needs.
A simple and portable way of computing your own sysid may be to serialize uname(), gethostid() and some inodes like /home or your application homedir (obtained with stat()) etc. in a string and hash It.

How can I find the version of the Fedora I use?

sudo find /etc | xargs grep -i fedora > searchFedora
gives:
/etc/netplug.d/netplug: # At least on Fedora Core 1
...
But see the Fedora version in the /etc/netplug.d/netplug file. Is it serious?
cat /etc/issue
Or cat /etc/fedora-release as suggested by #Bruce ONeel
You can also try /etc/redhat-release or /etc/fedora-release:
cat /etc/fedora-release
Fedora release 7 (Moonshine)
The proposed standard file is /etc/os-release. See http://www.freedesktop.org/software/systemd/man/os-release.html
You can execute something like:
$ source /etc/os-release
$ echo $ID
fedora
$ echo $VERSION_ID
17
$ echo $VERSION
17 (Beefy Miracle)
The simplest command which can give you what you need but some other good info too is:
hostnamectl
You could try
lsb_release -a
which works on at least Debian and Ubuntu (and since it's LSB, it should surely be on most of the other mainstream distros at least). http://rpmfind.net/linux/RPM/sourceforge/l/ls/lsb/lsb_release-1.0-1.i386.html suggests it's been around quite a while.
cat /etc/*release
It's universal for almost any major distribution.
[Belmiro#HP-550 ~]$ uname -a
Linux HP-550 2.6.30.10-105.2.23.fc11.x86_64 #1 SMP Thu Feb 11 07:06:34 UTC 2010
x86_64 x86_64 x86_64 GNU/Linux
[Belmiro#HP-550 ~]$ lsb_release -a
LSB Version: :core-3.1-amd64:core-3.1-noarch:core-3.2-amd64:core-3.2-noarch:deskt
op-3.1-amd64:desktop-3.1-noarch:desktop-3.2-amd64:desktop-3.2-noarch
Distributor ID: Fedora
Description: Fedora release 11 (Leonidas)
Release: 11
Codename: Leonidas
[Belmiro#HP-550 ~]$
These commands worked for Artik 10 :
cat /etc/fedora-release
cat /etc/issue
hostnamectl
and these others didn't :
lsb_release -a
uname -a
What about uname -a ?
On my installation of Fedora 25 (workstation) all of the distribution ID info was found in this file:
/usr/lib/os.release.d/os-release-workstation
This included,
NAME=Fedora
VERSION="25 (Workstation Edition)"
ID=fedora
VERSION_ID=25
PRETTY_NAME="Fedora 25 (Workstation Edition)"
<...>
VARIANT="Workstation Edition"
VARIANT_ID=workstation
You can simply run this command to get the version number:
rpm -E %fedora
output:
uname -a works with my fc11
use commmand , screenfetch
output format info.

Resources