Finding system information from the command line
At Your Command
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.
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.
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).
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.
If you are seriously tracking memory usage, then -s[SECONDS] updates the results at the interval given by .
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.
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).
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.
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.
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.
Linux users can now download and install the Windows code editor
New initiative will address security and interoperability concerns around container technology.
Developers can use RHEL as a development platform without a subscription fee.
Windows users will soon have native access to the Bash shell.
Improvements to SMTP will provide better guarantee of confidentiality
Graphics vendor embraces new reality in Linux graphics
Pioneer Ray Tomlinson bequeathed the @ sign to billions of Internet users
Redmond says its classic database tool will run without Windows
New intrusion technique affects most non-Bluetooth wireless mice
GENIVI Alliance announces the release of the first beta of the GENIVI Demo Platform ivi9.