Open Source

Mine /proc for system information

In this tip, Vincent Danen shows you the virtual filesystem /proc for Linux. The script examples here demonstrate the wealth of system information that /proc puts at your fingertips.

The /proc virtual filesystem is one of the most interesting virtual filesystems available on Linux. Here you can see more information about your running system than you would know what to do with, including system information, memory information, CPU information, and much more.

Mining /proc for information can be invaluable if you need to find something out, such as what kind of processor the system is running or how much memory it has available.

Here is a script that illustrates some of the things you can do with /proc and how you can and format it for display. Whether this is just for curiosity or part of inventory or logging for a particular system, this script can be used and extended in a variety of ways. Its main purpose here is to show how much information can be gleaned from /proc.

echo "System Information"
echo "—————————"
echo "  hostname: `cat /proc/sys/kernel/hostname`"
echo "  kernel:   `cat /proc/sys/kernel/osrelease`"
echo ""
echo "Mounted Filesystems"
echo "—————————-"
cat /proc/mounts | sort
echo ""
echo "Available SWAP"
echo "———————"
cat /proc/swaps
echo ""
echo "Disk Devices By Controller"
echo "—————————————"
for dev in `ls /proc/ide | grep ide`; do
    echo "${dev}:"
    for disk in `ls /proc/ide/${dev}`; do
        if [ -f ${pdev}/driver ]; then
            echo "    /dev/${disk}"
            echo "    ————"
     [[ -f ${pdev}/model ]]    && echo " model:    `cat ${pdev}/model`"
     [[ -f ${pdev}/cache ]]    && echo " cache:    `cat ${pdev}/cache`"
     [[ -f ${pdev}/capacity ]] && echo " capacity: `cat ${pdev}/capacity`"
     [[ -f ${pdev}/media ]]    && echo " type:     `cat ${pdev}/media`"
     echo ""
echo "CPU Information"
echo "———————-"
cat /proc/cpuinfo

Click on Listing A to see what the output of this script might look like.

Delivered each Tuesday, TechRepublic's free Linux NetNote provides tips, articles, and other resources to help you hone your Linux skills. Automatically sign up today!

About Vincent Danen

Vincent Danen works on the Red Hat Security Response Team and lives in Canada. He has been writing about and developing on Linux for over 10 years and is a veteran Mac user.

Editor's Picks

Free Newsletters, In your Inbox