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.
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).
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 .
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.
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.
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.
-
DebConf24 to be Held in South Korea
Busan will be the location of the latest DebConf running July 28 through August 4
-
Fedora Unleashes Atomic Desktops
Fedora has combined its solid distribution with rpm-ostree system to make it possible to deliver a new family of Fedora spins, called Fedora Atomic Desktops.
-
Bootloader Vulnerability Affects Nearly All Linux Distributions
The developers of shim have released a version to fix numerous security flaws, including one that could enable remote control execution of malicious code under certain circumstances.