This is a read-only archive. Find the latest Linux articles, documentation, and answers at the new Linux.com!

Linux.com

Feature: System Administration

CLI Magic: Viewing system information

By Bruce Byfield on January 08, 2008 (9:00:00 AM)

Share    Print    Comments   

GNU/Linux is bursting with information about the system on which it runs. The system's hardware and memory, its Internet link and current processes, the latest activity of each user -- all this information and more is available. And, despite such desktop tools as the KDE Control Center or GNOME's System Monitor, the easiest place to get all the system information available is still the command line.

In many cases, you can view system information via specific commands. Some of these commands are written specifically to give information, while other commands that are mainly intended to alter the system in some way just happen to include parameters for viewing the current state of the system.

In other cases, you can view system information through log or configuration files or the /proc virtual filesystem. Many such files are written in plain text, so all that you need to view them are basic commands that output a file's content to the command line, such as cat, less, or more.

Commands for reading system information

One of the simplest commands for reading system information is arch, which gives back the architecture of your computer, listing Pentiums as i586 and a Pentium II or greater or i686. However, a more complete analysis of your system is available using uname -a, which lists in a single line the operating system, local host, kernel release and build information, and the processor type. You can flesh out this information further by using fdisk -l to list partitions, and swapon -s for information about any swap partitions that you are running. For information about current system usage, including which users are currently logged on and what processes they are running, a simple w suffices. To learn which kernel modules are loaded, run lsmod.

Several commands report on memory. For RAM, the basic command is free -m, which tells you the total amount of RAM and swap space on your system, as well as how much of each is used and how much is free. For hard drive space, you can use the df command to report on the entire system, or specify the device block of a particular filesystem. An especially useful version of the command is df -hiT, which lists the size of each filesystem, how much space is used and available on it, and its inodes and its mount points. If you need to know the size of a specific file or directory, use du path or ls -s du path.

If you are interested in your Internet connection, then nslookup host-server will give you the domain name and address. The dnsdomainname command displays the domain name, and so will hostname -d, while hostname -i returns your IP address.

Another set of commands gives you information about the processes on the system. One of the most commonly used process commands is top, which gives you a continuously updated display of the processing using the most memory on the system until you close it by pressing Ctrl-C. For a complete list of running processes, enter ps auS (note the lack of a hyphen in front of the parameters). Another view of current processes comes from pstree, which displays parent and child processes -- that is, which processes are started by other processes. Alternatively, you can use fuser -c process to check whether a process is using the contents of the current directory.

Still another set of commands allows you to gather information about users and what they are doing. The command group user tells you what groups the designated user belongs to, while id user gives the same information, in addition to the user and group IDs. The command finger user will give you more information, including the last time the user logged on to the system and whether the use has mail waiting in /var/mail. And, should you really get stuck, perhaps because you have been logging in and out of system accounts, you can use the whoami command to orient yourself.

Other information sources

Besides specific commands, you also have several other sources of system information. One is the collection of logs in /var/log, which contain the latest information about what is happening on your system. For instance, as you can tell from the names, kern.log records kernel activity, while user.log tells you who is logged on to the system and what they have been doing recently. If you are troubleshooting, you can keep a log open and constantly updated with the command tail -f logfile.

Most logs can be read using standard the standard reading commands, but, depending on your distribution, some may be in a specialized format that requires a special command to read. For example, on Debian, the /var/log directory includes such files as dmesg, which records the most recent system boot, and faillog, which records the last time users tried to log in, and lastlog, which lists users and the last time they logged in, all of which are viewed using commands with the same name as the log.

Another prime source of information is the /proc directory, the virtual filesystem that contains current information about everything from the hardware and the kernel through to the processes now running on the system. Some of the information is stored a directory level or two down, such as the list of sound cards in /proc/asound/cards or the list of SCSI devices in /proc/scsi/device_info. Just be sure that all you do is read the contents of /proc; deleting, moving, or editing any of the files could cause a system crash.

Configuration files such as /etc/fstab, which lists the available filesystems, are also a useful source of information. In fact, most of /etc is worth knowing your way around, especially when you are troubleshooting specific programs.

The advantage that all these sources have is that, instead of needing to remember specific commands to get the information you want, all you need to do is display the information. Most, if not all, the information you can get from specific commands is also available from these sources. For instance, the command swapon -s gives you the same information as cats /proc/swaps.

Whatever source of information you use, a GNU/Linux system is full of information about itself, all of which is available from the command line. All you need to supply is a willingness to dig for it.

Bruce Byfield is a computer journalist who writes regularly for Linux.com.

Share    Print    Comments   

Comments

on CLI Magic: Viewing system information

Note: Comments are owned by the poster. We are not responsible for their content.

CLI Magic: Viewing system information: A replacement for top

Posted by: Anonymous [ip: 70.224.197.226] on January 08, 2008 10:07 AM
I may suggest using `htop` in place of `top`, to get much, much more information. The `top`-like graph, `uptime` information, and read-at-a-glance CPU, memory, and swap-space graphs are the most prominent (and useful) pieces of data, but if you like, you can also `renice` (change the nice value, or priority, of a process), send `kill` signals 0 through 31 to a process, or see a tree of parent/child processes. And the colored-by-default output is much easier to analyze than the standard black-and-white of top.

#

Re: CLI Magic: Viewing system information: A replacement for top

Posted by: Anonymous [ip: 90.192.66.210] on January 08, 2008 09:18 PM

CLI Magic: Viewing system information

Posted by: Anonymous [ip: 89.216.169.235] on January 08, 2008 10:14 AM
"... information as cats /proc/swaps ..."
cats? i think it's cat :)

#

CLI Magic: Viewing system information

Posted by: Anonymous [ip: 10.5.10.99] on January 08, 2008 10:39 AM
Some other useful tools are multitail which give a colorful output to your logs and you can view many files simultaneously. There is also lshw which gives you an output of all the hardware devices on your system.

#

CLI Magic: Viewing system information

Posted by: Anonymous [ip: 198.208.10.18] on January 08, 2008 11:29 AM
i can quit top pressing "q" :P

#

CLI Magic: Viewing system information

Posted by: Anonymous [ip: 196.15.16.20] on January 08, 2008 11:38 AM
For checking h/w related information - "dmidecode" is good.

- http://unixfo.blogspot.com

#

CLI Magic: Viewing system information

Posted by: Anonymous [ip: 10.150.150.203] on January 08, 2008 12:09 PM
I think the article gave commands that are common to all distros. Most of these others you are suggesting are distro specific. Nice informative article otherwise. Thanks Bruce.

#

CLI Magic: Viewing system information

Posted by: Anonymous [ip: 64.200.163.164] on January 08, 2008 01:27 PM
Don't forget the excellent 'dmidecode' command to learn the details about the hardware and drivers the system is running on. This command will give you much more than most folks will ever need. See the man pages for more information or this article from Linux.com <http://www.linux.com/articles/40412>.

#

CLI Magic: Viewing system information

Posted by: Anonymous [ip: 85.180.245.247] on January 08, 2008 01:31 PM
Shouldn't this be "ls -s path" instead of "ls -s du path"? Great article otherwise, didn't know some of the commands; I'm pretty much a linux newbie and only noticed the error because I actually typed in that command :o) ). Thanks!

#

Re: CLI Magic: Viewing system information

Posted by: Anonymous [ip: 137.48.24.32] on January 09, 2008 01:45 PM
Also I think what he was going for was "ls -s path | du". He forgot the pipe "|".

#

CLI Magic: Viewing system information

Posted by: Anonymous [ip: 216.6.118.231] on January 08, 2008 02:15 PM
A ton of useful Linux and Unix commands can be found at http://www.coolcommands.com

#

CLI Magic: Viewing system information

Posted by: Anonymous [ip: 127.0.0.1] on January 08, 2008 03:10 PM
Also, ps afuxww and pstree are quite useful. Both produce a tree listing of parent/child processes.

#

CLI Magic: Viewing system information

Posted by: Anonymous [ip: 122.168.36.22] on January 08, 2008 06:04 PM
not exactly comprehensive but nicely done anyway. thanks

#

CLI Magic: Viewing system information

Posted by: Anonymous [ip: 137.48.24.32] on January 09, 2008 01:51 PM
"hostname -i" displays what's listed in /etc/hosts as the IP address, which may or may not actually be the IP address of the running system. "ifconfig" is a better alternative.

#

CLI Magic: Viewing system information

Posted by: Anonymous [ip: 121.223.22.152] on January 09, 2008 02:05 PM
Another tool I find useful for checking the state of the X server is "xrestop"

#

CLI Magic: Viewing system information

Posted by: Anonymous [ip: 86.27.66.2] on January 09, 2008 02:39 PM
hehe pstree is cool, another for my google notebook

Here are others that I use....

sudo lshw (lists the hardware detection results)

lsusb (lists the usb devices conencted to the machine)

lspci -v (list all pci devices)

lsof -p 12345 (the -p switch lists the open files for a given process ID)

blkid (show the uuid of partitions to use with fstab)

#

CLI != magic

Posted by: Anonymous [ip: 169.233.25.12] on January 10, 2008 02:40 AM
How many times must I say this? The command line is not some magical thing. Please stop spreading misinformation.

#

CLI Magic: Viewing system information!!!!!!!!!!!!!

Posted by: Anonymous [ip: 125.19.57.227] on January 24, 2008 07:03 AM
Amazing!!!!!
After studying this article....i Came to know so many new commands of the LINUX....IT is good article..I hope it would be more beneficial to a Linux Bigginer

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya