we can kow ubuntu versions with any one of following commands
lsb_release -a
cat /etc/os-release
hostnamectl
we can kow Centos versions with any one of following commands
you need to execute below command how to know version with lsb based command
yum install redhat-lsb
lsb_release -d
Description: CentOS Linux release 7.4.1708 (Core)
lsb_release -r
Release:7.4.1708
lsb_release -a
hostnamectl
/etc/centos-release
/etc/os-release
/etc/redhat-release
/etc/system-release