Linux

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.

#!/bin/sh
 
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
        pdev="/proc/ide/${dev}/${disk}"
        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 ""
        fi
    done
done
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 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.

12 comments
Jaqui
Jaqui

the /proc virtual filesystem is depreciated and won't be as full of information about the system. the udev system that is the current system designed for usb devices is actualy replacing /proc for far more than just usb devices. When you add the HAL [ Hardware Abstraction Layer ]system you find that proc is not used at all. Most distros are almost completely switched to udev and HAL, with almst nothing left in the /proc system.

BALTHOR
BALTHOR

Does all of Linux works this way?Would I need a script to get on the Internet with Linux?

stress junkie
stress junkie

I hate the fact that this file system is accessible to normal users. It makes too much configuration information accessible to anybody that can log on. Normal users don't need to see system configuration settings. It's a security hole.

garnerl
garnerl

Yes, this is Linux, in its entirety. These few lines encompass the entire OS and all related software.

grephead
grephead

Keep in mind that Windows started as a user based (workstation) and expanded into the server area. Unix based systems are meant to be workhorses. You can use a GUI with Linux just like Windows - but you can cut that off if necessary - unlike Windows. Administration practices aren't going to be identical. In my experience I could easily administer 200+ Linux systems with good scripting and ssh keys without using a GUI at all. I surfed the internet on my Windows workstation ;-).

lesko
lesko

what you saw is like "cmd" in windows xp or "command" in windows 9.x or dos (command.com) then doing a bunch of commands like chkdsk ver etc. I agree with the other post try a live cd distribution ... I think PC Linux OS is highly rated so is Simply Mephis you can download pclinuxos here http://www.pclinuxos.com/ and simply mephis from http://www.mepis.org/ enjoy and have fun

shuubz
shuubz

sounds like a troll, so sarcasm is appropriate: yes, all linux works this way. you have to write scripts for everything, including checking your email, going online, looking into folders; even logging in requires extensive shell programming (this presents an interesting chicken-egg dilemma). much like a mainframe, unix and linux are not intended for human use, they were actually created for robots by robots, hence the popular acronym, FRBR. now, sarcasm aside (for people who actually do want the answer, in all seriousness): unix and linux can (and often do) have very pretty and/or useful GUI; for example, Mac OS X is a true unix, with some of the finest GUI design available. but if you delve into the system, it is still a flavor of unix, and you can get to the same command prompt available on a linux box. some of the more esoteric functionality (such as the firmware version of your hard drive) is most easily accessed with a code hack, such as the one above (or command from command line), but the information is usually available within the operating system out of the box, and often requires no further software install. linux and unix are about choice and options, but with choice comes responsibility. it's not for everybody. some people prefer to be told what to like and how to do things.

tommy higbee
tommy higbee

The advantage of the /proc system is that it makes it easy to read system information from a script or program. Linux certainly makes far more use of scripts than Windows. However, it's possible to use Linux just like Windows and never touch a command line. But if you're doing system administration on Linux, you'll probably take full advantage of its scriptability. Don't be too quick to form an opinion of Linux. There's a lot more to an elephant than a trunk!

stress junkie
stress junkie

Linux can run its own version of GUI called X or X Windows. There are applications that run in this GUI environment. Some of them are for system administration. Linux users probably use scripts more than Windows users but there is a lot that you can do with GUI applications, including connecting to the Internet. The amount of scripts and command line that a Linux users has to do depends on which Linux distribution you choose. Some have a lot of GUI applications while others have no GUI at all, but it can always be added later.

guygo
guygo

Who ya' callin normal? I have bash and Perl scripts that pull from /proc a lot, but I wouldn't call me a "normal" user. Using /proc is like mucking with the registry in Windows: Use caution, back yourself up rigorously, know what you're getting into. One of the beauties of Linux is that it is all configurable via text files. The /proc filesystem is a nice source of platform-dependant text strings. I'm sorry to hear udev is depreciating /proc.

Jaqui
Jaqui

most distros I have used have it system only access, for exactly that reason. the UID has to be < 500 to have any access to proc with most, even read access isn't permitted.

EjayHire
EjayHire

This is kind of a rough example if you are new to linux. I think the author was just trying to convey that there is a lot of useful information buried in /proc for system administrators. Will a user ever 'cat /proc/sys/net/ipv4/ip_forward' to see if network packet forwarding is turned on? Probably not, and there really is no reason to. The same setting is buried under the routing and remote access MMC in windows, and I wouldn't expect a user to go in there either. If you want to give Linux a test drive, You can get a "LiveCD" from Knoppix. A LiveCD is a full installation of Linux that runs right from the CD, without damaging your windows installation. It has a huge number of applications built in, and a really addictive game called Frozen Bubble. ;) Good Luck, -ejay