FreeBSD version from filesystem

One way to do it is using file(1) :
Code:
% file /bin/sh
/bin/sh: ELF 64-bit LSB executable, x86-64, version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 12.0 (1200506), FreeBSD-style, stripped

% file /usr/local/poudriere/jails/110arm/bin/sh
/usr/local/poudriere/jails/110arm/bin/sh: ELF 32-bit LSB executable, ARM, EABI5 version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 11.0 (1100122), FreeBSD-style, stripped
 
The file you're actually looking for is the kernel and it's the authority of installed version.
You can get the information out of it using freebsd-version, which exists as /bin/freebsd-version
It's a shell script, rather difficult to read in case you want to write your own.
 
You also have __FreeBSD_version in /usr/include/sys/param.h
 
I guess this identifies the version as 13.1.....

#define __FreeBSD_version 1301000 /* Master, propagated to newvers */
 
Nice, it's good to know that trick.
I do like the answer from @hukadan, but it doesn't hurt to have many solutions.
In my case:
Code:
~ >> file /bin/sh | awk -F, '{print $6}' | sed 's/ for //'
FreeBSD 13.2
~ >>
~ >> awk '/#define __FreeBSD_version/ {print $3}' /usr/include/sys/param.h
1302001
I've been playing with awk lately...
 
Modern installations have a /etc/os-release you can check.

Code:
% cat /etc/os-release
NAME=FreeBSD
VERSION="13.2-RELEASE-p3"
VERSION_ID="13.2"
ID=freebsd
ANSI_COLOR="0;31"
PRETTY_NAME="FreeBSD 13.2-RELEASE-p3"
CPE_NAME="cpe:/o:freebsd:freebsd:13.2"
HOME_URL="https://FreeBSD.org/"
BUG_REPORT_URL="https://bugs.FreeBSD.org/"
Code:
% cat /etc/os-release
NAME=FreeBSD
VERSION="12.4-RELEASE-p5"
VERSION_ID="12.4"
ID=freebsd
ANSI_COLOR="0;31"
PRETTY_NAME="FreeBSD 12.4-RELEASE-p5"
CPE_NAME="cpe:/o:freebsd:freebsd:12.4"
HOME_URL="https://FreeBSD.org/"
BUG_REPORT_URL="https://bugs.FreeBSD.org/"
Code:
$ . /etc/os-release ; echo "${NAME} ${VERSION}"
FreeBSD 12.4-RELEASE-p5
 
Indeed, I keep forgetting this one I never remember that name I don't even know how that's possible, I mean there is the word "release" in its name! it should be obvious.
Plus like you said it's well known because it's on most Unix OSes.
The thread is bookmarked, hope I'll remember ... haha.
 
Back
Top