tail -f findings.out

« Improving command line efficiency via Bash history

Python Tip: Create a test dictionary quickly »

Convenient OS and hardware summary information

There are quite a number of ways to get information on your OS and especially your hardware on a Linux system. Instead of remembering them all and sorting through their output, I put together a pair of functions that provide useful summary information at a glance. While the more detailed tools are indispensable when you need, well, more detailed information, these might fit the bill most often when you just need to find out what sort of system you are dealing with.

OS and Kernel

This function doesn’t show a lot of information, but for me it makes things more intuitive. It took a while before uname came naturally. So I created:

1
2
3
4
5
6
7
function os {
    export OPER_SYS_1="`uname -s`"
    export OPER_SYS_2="`cat /etc/issue | head -n 1`"
    export KERN_INFO="`uname -r`"
    echo -ne "\033[31mOS:\033[0m " && echo "$OPER_SYS_1, $OPER_SYS_2"
    echo -e "\033[32mKernel:\033[0m $KERN_INFO"
}

Which will give you something like:

Hardware

While there is an obscene amount of information you can gather from Linux about your machine’s hardware, you often don’t necessarily care about most of it. Most often you probably just need basic stats such as total RAM, CPU speed and HDD space. This function will give you that in a compact display. I also threw in some motherboard information because I often need to check the manual for a board online and don’t want to have to open the case just to get the model:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function hw () {
    export MOBO_MAN="`sudo dmidecode --type baseboard | grep 'Manufacturer' | cut -d' ' -f2-`"
    export MOBO_MOD="`sudo dmidecode --type baseboard | grep 'Product' | cut -d' ' -f3-`"
    export CPU="`cat /proc/cpuinfo | grep 'model name' | cut -d' ' -f3-`"
    export RAM_TOTAL_KB="`cat /proc/meminfo | grep MemTotal | awk '{print $2}'`"
    export HDD_INFO="`sudo fdisk -l | grep Disk | grep -v identifier`"
    echo -e "\033[1;34mHardware\033[0m:"
    echo " * Motherboard:"
    echo "   * Manufacturer: $MOBO_MAN"
    echo "   * Model: $MOBO_MOD"
    echo " * CPU(s):"
    echo "$CPU"
    echo " * Total RAM: $(($RAM_TOTAL_KB / 1024)) MB"
    echo " * HDD info: "
    echo "$HDD_INFO"
    echo
}

The result:

Putting them together

I find I most often want to see information on the OS and hardware together. To achieve that, just create a simple alias such as:

1
alias system="os && hw"

Then simply running “system” will show you basic information about the system you are on. Pretty intuitive!

Notes

  • I made use of the DMI via dmidecode to provide some of the hardware information. Although I have never had any problems with it, it is possible for this information to be inaccurate. From everything I have read, it seems to be reliable on all common Linux systems and platforms.
  • If you run this on, say, a virtual private server (pretty common as a hosting solution), you will likely not have permission to get some of the hardware info, even running it with sudo, simply because of how your VPS is setup. Not much you can do about that, but the commands will still show you what output they can.
Share and Enjoy:
  • email
  • LinkedIn
  • Slashdot
  • StumbleUpon
  • Technorati
  • Netvibes

Post to Twitter Post to Delicious Post to Digg Post to Reddit

Possibly Related (no promises):

  1. Useful grep incantations
  2. Get useful image information on the command line
  3. Viewing all users on a Linux system
  4. Useful Bash functions to determine OS and more

Related posts brought to you by Yet Another Related Posts Plugin.

Tags: , , , ,
January 3, 2009 - 8:13 PM
Leave a reply

Subscribe without commenting

Twitter links powered by Tweet This v1.6.1, a WordPress plugin for Twitter.