Finding system information from the command line

At Your Command

© Sasha Radosavljevic, 123RF

© Sasha Radosavljevic, 123RF

Article from Issue 105/2009

The command line provides a plethora of information that you cannot obtain from the desktop.

The command line is an interface designed to give you full control over the system when you are logged in as root. Because information is needed for control, it's not surprising that the average free desktop contains dozens of commands designed to tell you exactly what is happening on your system. In fact, many commands give you so much more information than you could possibly be interested in that you might be tempted to shout, "Overshare!" in much the same tones you did when your roommate last gave you a play-by-play account of his or her most recent date.

To start, I will talk about some of the commands that can reveal most of the information you will likely want about your system. Many have no direct desktop equivalent, but if you are trying to manage a system, on however small a scale, you should find them useful.

Note that many of these commands are not available from everyday accounts. If you try one of them and the system claims that it does not exist, trying logging in as root or starting the command with sudo, and you should be in business.

General System Information

The most basic command for system information is uname, which gives you a grab bag of information about the system (Figure 1). Although you can choose which pieces of information to display, usually it is easier to simply list everything uname can give you by typing uname -a.

Figure 1: The uname command gives a grab bag of basic system information.

Uname's output with the -a option is a single line with information separated by spaces. From left to right, the information is the general name of the kernel, the name of your machine, the kernel version and when it was compiled, your processor type, and the operating system you are using.

If you want to know what kernel modules are in use, the command is lsmod – with no options (Figure 2). In fact, the command is so simple that it doesn't even have a man page. All lsmod does is list each kernel module, its size, and the modules that refer to it.

Figure 2: The lsmod command lists each kernel module installed. Note that this is only a small sampling of its output.

Memory Usage

On a modern system, hard drive space and system memory are less pressing concerns than they were five years ago. Still, enough songs and pictures can fill even the largest hard drive, and you do not need to go far into animation or sound mixing before you find yourself at the limits of both types of memory. Fortunately, you have several commands to help you track memory usage.

For hard drive memory, the basic command is df (short for disk space free). The command by itself lists memory on all partitions, or you can specify which partitions to display. To refine the command further, you can use the switch -type=[filesystem] and display only those partitions formatted with a particular filesystem, such as ext3 or ReiserFS. Another useful switch is -H, which displays in so-called "human-readable" form – for example, it would display a size of 269377692 as 270G (gigabytes) instead.

Whatever options you choose, df displays the total amount of space on the hard drive, the space used as both an amount and a percentage of the whole, the space free, and where each partition is mounted (Figure 3).

Figure 3: To check free hard drive space, use df.

In contrast, system memory is the RAM combined with the size of the swap partition, which you can discover with the free command (Figure 4). Just as with the df command, you can specify how memory statistics are displayed, but, in the case of free, you use either the option -m for megabytes or -g for gigabytes (options -k for kilobytes and -b for bytes are available, too, but neither is likely to get much use these days). Also, you might want to use -t to add a line to the output containing totals.

Figure 4: The free command shows the amount of system memory you have. System memory is the amount of RAM plus your swap partition.

If you are seriously tracking memory usage, then -s[SECONDS] updates the results at the interval given by .

Partition Information

The quickest source of information about how your hard drives are divided comes from displaying the contents of /etc/fstab. For example, on the machine I use, entering the command less /etc/fstab produces the results shown in Figure 5.

Figure 5: The fstab file has information about what drives are currently mounted.

From this information, I can quickly see that I have seven hard drive partitions (including one for Windows that isn't listed because I don't use it on /dev/sda1 and excluding /dev/sda3, which is an extended partition and therefore less important than the partitions that exist on it) and where each is mounted, the filesystem used to format each one, and the options with which each is mounted. To understand the filesystems, look for the -t option entry in the man page for the mount command. The -o option man page entry will give you a basic crib for the mounting options.

Should you want to know specifically what the swap partition on your system is doing, you can use the command swapon -s to see its size and how much of it is currently in use (Figure 6).

Figure 6: The swapon -s command tells you how your swap partition is functioning.

For more detailed information about all partitions, experienced users usually rely on the fdisk -l command (Figure 7). Although fdisk is the same basic command for creating and deleting partitions, you shouldn't be concerned – with the -l switch, it only displays where each partition starts and ends and how it is formatted. The command has the advantage over displaying /etc/fstab in that it shows the extended, as well as any unmounted, partitions.

Figure 7: The traditional way to read information about your hard drive partitions is the fdisk -l command.

However, even the venerable fdisk pales beside GNU Parted, the partition editor that comes with most distributions these days. If you enter the command parted, you start the application's own shell (Figure 8), which has its own set of basic commands. By entering help, you can get a full list of these commands, but the one you want here is print.

Figure 8: The GNU Parted shell's print command will tell you everything you want to know about your hard drive partitions, and then some.

The result is not only information about your hard drive's characteristics, but also each partition type (i.e., extended or logical) and any flags that might be on it, such as which one is marked as bootable. When you have the information you want, type quit to leave Parted's shell and return to Bash.

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Command Line – Probing /proc

    The mysterious /proc virtual filesystem is a rich mine of information about everything in your system.

  • Command Line: Encrypting Partitions

    Modern installers offer the option of encryption with just a few clicks, but you might want to take control of the process. We show how to encrypt your partitions safely without sacrificing convenience.

  • Command Line: Partitioning

    Despite the popularity of LVM, traditional partitioning is still preferred by some admins. We provide some tips to consider before choosing a partitioning scheme for your setup.

  • Captive NTFS

    Why reboot every time you need to access data on the other side of your dual boot system? We’ll introduce you to Captive NTFS – a free tool for reaching Windows NTFS partitions from Linux. We’ll also show you some handy tools for reading Linux partitions from Windows.

  • Data Rescue

    Armed with just standard Linux tools, users can recover files, resurrect partitions, and rescue damaged media.

comments powered by Disqus

Direct Download

Read full article as PDF:


njobs Europe
Njobs Netherlands Njobs Deutschland Njobs United Kingdom Njobs Italia Njobs France Njobs Espana Njobs Poland
Njobs Austria Njobs Denmark Njobs Belgium Njobs Czech Republic Njobs Mexico Njobs India Njobs Colombia