X
Tech

5 Linux commands you must know to keep your device running smoothly

If you want to know what's going on under the hood of your Linux operating system, these commands will tell you everything about system resources and running processes.
Written by Jack Wallen, Contributing Writer
Inside a System76 Thelio.
Jack Wallen/ZDNET

One of the many nice things about Linux is that there's always so much power at your fingertips. With that power comes great information that can help you troubleshoot issues or simply see how much RAM or storage is being used.

Over the years, I've come to depend on these tools, which are built into most Linux distributions and are fairly easy to use.

Also: The first 5 Linux commands every new user should learn

Before I dive into these commands, know that you might never use them. In fact, with today's GUI desktops, the goal should be to no longer have to depend on the command line. Of course, if you're working with a server, that's a different story. But as far as the desktop is concerned, you'll be glad you know them if the occasion ever arises.

With that said, let's jump to the commands.

1. top

The top command prints out a real-time list of Linux processes, which can be important should an app or process go awry and you need to find out which one. Top prints out a columned list that is broken down into the following:

  • PID - Process ID
  • USER - the owner of the listed process
  • PR - the process priority
  • NI - the nice value of the process (nice determines the process' priority)
  • VIRT - the amount of virtual memory the process is using
  • RES - the amount of resident memory the process is using
  • SHR - the amount of shared memory the process is using 
  • S - the status of the process (such as D - uninterruptable sleep, R - running, S - sleeping, T - stopped, and Z - zombie)
  • %CPU - the share of CPU time the process is using (since the last update)
  • %MEM - the share of physical memory the process is using
  • TIME+ - the total CPU time the process is using (in hundredths of a second)
  • COMMAND - the command associated with the process

Although you can define the content that is displayed, the default should work for most situations. The top command can also be helpful when using the kill command to end a runaway process (because you'll need to know the PID of the process in question).

To find out more about top, issue the command man top.

2. df

There are times when you might want to know how much of your local storage is in use. That's where the df command comes in. The df command presents a list of columns broken down into Filesystem, Size, Used, Avail, Use%, and Mounted on. Clearly, df is also useful to find out where a particular partition is mounted, but you'll mostly use this command to understand how much of your drive's storage has been used.

Also: The 6 Linux commands you need to know for user management

If you issue df without any options, the report will be in 1K blocks, which can be a bit of a challenge to understand. Instead, I prefer to run df -h (the h is for human readable), which presents the available space in GBs.

To find out more about df, issue the command man df.

3. ps

The ps command is rather important, as it reports a snapshot of the current running processes. In other words, ps lists out all running processes on your system. The thing about ps is that you need to know the right options to make it useful. If you simply issue the command ps, you'll only see two entries, bash and ps - which are the current processes you are running.

The better way to run ps is with the -aux option (which stands for all, user, and all processes owned by you). That command is:

ps -aux

Why is ps so important? It is the easiest way to locate a process ID associated with a command (far better than using top). You can even use ps with grep to find the process you're looking for. Say, for example, LibreOffice isn't responding and you need to kill it. To do that, you'll need the PID. If you don't want to scroll through the entire list of processes, you could issue something like:

ps -aux |grep libreoffice

This command will list only the processes associated with LibreOffice.

To find out more about ps, issue the command man ps.

4. free

The command free displays the amount of free and used memory in your system. Instead of using top, which might offer too much information, you can use free, which only lists memory and swap (if applicable). 

Also: My top 5 user-friendly GUI backup tools for the Linux desktop (and why you need one)

The output is formatted in columns of total (total installed memory), used (total used memory), free (total unused memory), shared (memory used by tempfs), buff/cache (sum of buffers and cache memory in use), and available (an estimation of how much memory is available for starting new applications without using swap).

The free command doesn't do anything else, but you can display the information in a human-readable form with:

free -h

To find out more about about free, issue the command man free.

5. lsblk

The lsblk command comes in handy when you need to mount a device or see where a device (a drive) is mounted. When you issue the lsblk command, you'll see output like this:

sdb       8:16   0 931.5G  0 disk  
└─sdb1    8:17   0 931.5G  0 part  /media/jack/MINA

This means that block device /dev/sdb1 is mounted to the folder /media/jack/MINA. One option I sometimes use is -f, which adds the filesystem type to the listing.

To find out more about lsblk, issue the command man lsblk.

These commands could come in handy someday. You may not need them at first (or ever) but knowing they exist (and their basic usage) can make troubleshooting your Linux system far easier.

Editorial standards