Linux tricks and tips.

July 27th, 2012

When you are working with several Linux distributions, it’s useful to be able to quickly see which one you are working on.

To get the version and distro that you are running.

# cat /etc/issue
Debian GNU/Linux 6.0 \n \l

This works on Red Hat (RHEL), Debian, OEL, Ubuntu, CentOS, etc.

You can also try…

 uname -a
Linux hostname 2.6.32-5-amd64 #1 SMP Sun May 6 04:00:17 UTC 2012 x86_64 GNU/Linux

Although this is far less useful, as it tells you the Kernal version you are running but nothing about your distro.

Here are a few more specific ways to get the same thing…

lsb_release -a (Debian based distros)
cat /etc/lsb-release (Ubuntu and other Debian based distros)
cat /etc/debian_version (Ubuntu and other Debian based distros)
cat /etc/oracle-release (Oracle Enterprise Linux - OEL)
cat /etc/redhat-release  (Red Hat Enterprise Linux - RHEL)

To work out how much memory you have installed…

cat /proc/meminfo

and the number + type of CPUs.

cat /proc/cpuinfo

If you are using Debian, then dpkg / aptitude are your package management tools (amongst others!)

dpkg -l List packages installed.
dpkg -s <package> Package status
sysv-rc-conf --list
sysv-rc-conf tomcat [on|off]
/etc/init.d/tomcat [start|stop|restart|status] 
service tomcat start | stop | restart (This works on Debian 6 and later)
(you need to replace "tomcat" with the service you are trying to start | stop)

Under RHEL, you should get familiar with yum and rpm.  It’s probably worth setting up your own local yum repository.

service –status-all
yum -y install tomcat    (the -y does it without asking, only use if you know what you are doing).
rpm -qa   (list all