Advanced Command Line Use — "In the Beginning there was Shell"

The Linux Filesystem

A big part of understanding Linux is to know your way around the filesystem.

Linux is configured using files stored in certain directories (/etc), program binaries are located in directories (/usr/bin etc.) and even access to devices like hard drives, networks adapters etc. are provided by file-like objects in a directory (/dev). Linux has this in common with most UNIX-like operating systems.

The following list gives you an overview of directories you’ll most likely be using:

  • /home: as the name suggest, this is where your users files and configuration reside. The data that you store here is in a subdirectory that normally has the same name as your login, such as /home/myuser.

  • Each user has their own subdirectory in /home. The permissions of these home directories on Fedora is set in a way that no user can look at the data of any other user (except for users with administrator rights who have access to all directories).

  • /etc: your global system configuration is stored here. We’re talking about network configuration, how hard drives are "mounted" into the filesystem, the name of your computer and more.

While Fedora KDE Plasma helps you configure your computer using the graphical user interface of System Settings, you can choose to edit configuration in /etc manually using a text editor.

To learn more about the Linux filesystem, have a look at the Filesystem Hierarchy Standard by The Linux Foundation. It lists system directories found on your computer and explains their purpose.

The Terminal Emulator & Shell

Parallel to the graphical interface of desktop environments lives the command line. To properly display and use the command line in a desktop environment, two components are needed:

  • Terminal Emulator: a program that lets you interact with the…​

  • Shell: the command processor for the command line.

The terminal emulator deals with your keyboard input to the shell and also the output that the shell generates by properly displaying it in a program window.

By using the shell, you unlock the full range and power of Linux commands.

Shell commands can:

  • browse the filesystem

  • copy, move and delete files

  • edit files

  • configure your computer

  • display information

  • install and remove software

  • connect to other computers

To use the shell, open the Application Launcher, navigate to "System" and click on "Konsole". Konsole is the standard terminal emulator that comes with KDE Plasma.

The command to learn commands is man. It lets you display manpages — manual pages — of most available commands. To open the manpage of the ls command, you would call:

$ man ls

Go ahead and run it, and learn what ls does - or at least learn the options that you call with ls.

You can scroll the manpage with the mouse-wheel, arrow or page up / down keys. To exit the manpage viewer, press q.

The default shell on Fedora is Bash. However, there are many other shells, too.

Here’s a list of commands we encourage you to explore which help you move around the filesystem of your computer:

  • ls

  • cd

  • cp

  • mv

  • rm (Careful!)

  • cat

  • less

Read the manpage of each command before using it!

There are two main editors that most people use:

Both editors' homepages have documentations sections and we suggest you familiarize yourself with one of these editors to be able to edit files in the terminal.

The shell IS powerful. You have complete control over your system. This includes the power to delete your files or break your system.

But don’t be afraid, be aware.

Understand what a command does before using it. Don’t copy and paste instructions from the internet or AIs without knowing what they will do. Being able to work in the terminal is essential to tackle advanced workflows.

If you’ld like to test shell commands but don’t feel safe, grab the USB drive you used to install Fedora, boot the live system and explore, or visit [webminal]. You won’t damage your installation as long as you don’t mount your hard drive. Run man mount if you want to know what we’re talking about .

What is sudo?

sudo stands for "substitute user and do". Annecdotally, it also stands for "superuser do".

Calling any command prefixed with sudo will be run as the superuser, also known as the 'root' account. Only Administrators can run sudo. This keeps normal users from running commands that could break the system.

Commands that can permanently change the system usually require sudo. If you run a command, and the shell tells you "this command must be run as root", you need to prefix it with 'sudo' to actually use it. Before you do, think about what you are doing.

Be aware when copying and pasting commands from the internet or AI that are prefixed with sudo. It is possible to add malicious code to you Linux system. Don’t paste code you don’t understand.

Refer to man sudo to learn more.

Command line package management

To show you how to install new software via the command line, we will give the same instructions as we did for installing the same games as we did in the Gaming section above - but this time, we won’t use Discover, we will use the command line in Konsole.

Since installing packages is a system operation that can only be executed by administrators, you will be using sudo.

Intro to dnf

dnf stands for "dandified yum". Don’t ask why . yum is the older package manager for another Linux distribution, Red Hat.

A package manager is software that installs, manages, updates and removes software.

Essential dnf commands are:

  • install

  • upgrade

  • remove

If you would like a deep-dive into dnf, DNF Commands is quite advanced.

Installing Software via Command Line

$ sudo dnf install <name_of_software>

e.g. to install:

$ sudo dnf install xeyes

and to remove e.g.:

$ sudo dnf remove xeyes

Installing Games with the Command Line

Supertuxkart:

$ sudo dnf install supertuxkart

Oad:

$ sudo dnf install 0ad

Luanti:

$ sudo dnf install luanti

Xonotic:

$ sudo dnf install xonotic

Updating Fedora via Command Line

$ sudo dnf upgrade

Viewing processes on the shell

Each running program or script on Linux is called a process. A process has a number of properties, among others:

  • a process ID, the PID

  • an owner

When the system boots, the first process that is spawned is "systemd". Hence it has the PID "1". All processes are spawned by a parent process. You will notice later that most system processes that help running your computer have "1" (systemd) as their parent process. One of systemd’s jobs is to start all processes necessary to have a working computer.

To see what processes are running, issue the ps command in the shell after reading its manpage. A very common way to call ps is:

$ ps -elf

which will display detailed process information.

Another useful command to see processes with their respective statistics is top. It will show you CPU and memory usage as well as PIDs and process names and owners. A more modern version of top is btop which needs to be installed by typing:

$ sudo dnf install btop

Run btop in Konsole and explore the information it gives you.

How to manage processes

Linux has its faults, so do programs. It can happen that programs crash and need to be terminated. You can do it by:

  • finding the PID using ps or top

  • issuing the kill command

Despite its name, kill is not meant to only kill a process. It sends a so called signal to a process. Let’s say the program that doesn’t respond anymore has the PID "123". You would first try to send it the SIGHUP signal to terminate it:

$ kill -1 123

Note that "-1" is synonymous for "-SIGHUP". Check again using ps — if the process is still running, it’s time for the sledgehammer: SIGKILL:

$ kill -9 123