Linux - The fundamentals

Last month, I have given a class about Raspberry Pi programming. It was awesome, and I really like to help others understanding new things. To my surprise, some attendees weren't having any idea about Linux commands at all. We often forget, that some of us are just starting their journey.

Linux - The fundamentals
© 2022, Daniel Schier, CC BY-SA 4.0

Last month, I have given a class about Raspberry Pi programming. It was awesome, and I really like to help others understanding new things. To my surprise, some attendees weren't having any idea about Linux commands at all. We often forget, that some of us are just starting their journey.

I hope this article helps you, to navigate Linux based operating systems easier and dig into the world of Open Source software.

Working with Linux

Let's assume you started your journey today. After the first guide of "How to install ..." you will, most likely, start on a desktop or in an SSH session. It is very common to know some CLI commands to work with Linux, but why is it so? Let me explain this a bit.

Linux, or to be precise, Linux based operating systems can come in very different variations. You can have a server, a desktop, an IoT device or a cloud instance. You can run Fedora, CentOS or Ubuntu and many others. All of them are having one thing in common: The terminal.

Furthermore, Linux can be customized a lot. You may use a different desktop or other customizations. This makes screenshot guides very hard to understand. A guide for Linux with KDE will be way different from a guide for Linux with GNOME desktop. Even the version between two desktops can lead to different behaviors.

But, most terminal commands will be universal. Copying a file in the terminal works in almost all Linux based operating systems. The same can be said about editing files and the most basic tools.

Therefore, let's start using them.

Information

I assume, the first thing on an unknown machine is, to get some information about it. Below, you can find some commands with the output from Fedora 36. You can compare it to your installation, if you like.

# Get the Kernel information
$ uname -a
Linux greentea.local 5.18.19-200.fc36.x86_64 #1 SMP PREEMPT_DYNAMIC Sun Aug 21 15:52:59 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

# Check the OS information file
$ cat /etc/os-release 
NAME="Fedora Linux"
VERSION="36 (Workstation Edition)"
ID=fedora

# Get CPU information
$ lscpu 
Architecture:            x86_64
  CPU op-mode(s):        32-bit, 64-bit
  Address sizes:         39 bits physical, 48 bits virtual
  Byte Order:            Little Endian
CPU(s):                  8
  On-line CPU(s) list:   0-7

# Get memory information
$ lsmem
RANGE                                  SIZE  STATE REMOVABLE  BLOCK
0x0000000000000000-0x0000000067ffffff  1,6G online       yes   0-12
0x0000000100000000-0x000000048fffffff 14,3G online       yes 32-145

Memory block size:       128M
Total online memory:    15,9G
Total offline memory:      0B

# Get device information (PCI)
$ lspci
00:00.0 Host bridge: Intel Corporation 11th Gen Core Processor Host Bridge/DRAM Registers (rev 01)
00:02.0 VGA compatible controller: Intel Corporation TigerLake-LP GT2 [Iris Xe Graphics] (rev 01)

# Get device information (USB)
$ lsusb
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

# Get harddisk information
$ lsblk 
NAME                                          MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS
zram0                                         252:0    0     8G  0 disk  [SWAP]
nvme0n1                                       259:0    0 931,5G  0 disk  
├─nvme0n1p1                                   259:1    0   600M  0 part  /boot/efi
├─nvme0n1p2                                   259:2    0     1G  0 part  /boot
└─nvme0n1p3                                   259:3    0 929,9G  0 part  
  └─luks-6fa98e57-96d5-4edc-a069-e1b326d0365f 253:0    0 929,9G  0 crypt /home
                                                                         /

After knowing where you are, you may want to navigate a bit. This can be done with a graphical tool, too. For me, the command line is way faster and works on a Raspberry Pi, Server and Workstation in the same way.

Furthermore, Linux has a pretty strict way to store files. The standard is known as the Filesystem Hierarchy Standard. Sounds complicated, but it is not. First, you need to know that there are no "drives" like for Windows. Instead, everything is sorted in a hierarchical directory layout. This layout follows the mentioned standard.

The most important paths are listed below:

/
|- /root	# the home directory for the root user
|- /home	# all user home directories are located here
|- /usr		# stores most binaries and executables (aka programs)
|- /etc		# most system side configuration is stored here
|- /var		# stores variable data like logs or web sites
|- /tmp		# stores temporary data

With just a couple commands, you can navigate here:

# List content
$ ls

# Also show hidden files
$ ls -a

# use a more explanatory list format
$ ls -l

# change to a directory
$ cd /path/to/directory

# copy a file
$ cp /path/to/source /path/to/destnation

# copy a directory, including its content
$ cp -r /path/to/source /path/to/destination

# output the contant of a file
$ cat /path/to/file

# alternatively use less for the same
$ less /path/to/file

# search in a file
$ grep SEARCHTERM /path/to/file

This should allow you to get an idea of the filesystem and directory layout.

Editing

Now, after discovering the files, you might edit a configuration. This is also one of the major ways to configure Linux programs. Most of them can be configured with simple text files. In Linux, two commands are very commonly used for the same.

# edit a file with the nano editor
$ nano /path/to/file

# or use vim
$ vim /path/to/file

Depending on the Linux distribution, one of them or both may be installed.

Packages

Apropos installed. Linux is known for its repository managed packages. Instead of searching for a download on many different websites, the distribution maintainers are providing a repository where you can search and install supported packages.

But, there is one downside. Depending on the distribution, you may need different package management tools. I will cover three of them below.

Fedora, Red Hat, CentOS, AlmaLinux, Rocky Linux

For the Red Hat family, DNF is the package management software. It handles RPM packages.

# search for a packages
$ dnf search SEARCHTERM

# install a package
$ sudo dnf install PACKAGE

# update packages
$ sudo dnf upgrade

# Uninstall a package
$ sudo dnf remove PACKAGE

Ubuntu, Debian, Pop!OS, Elementary OS, Linux Mint

The Debian Family uses the APT package manager. It handles DEB packages.

# update package cache
$ apt update

# search a package
$ apt search SEARCHTERM

# install a package
$ sudo apt install PACKAGE

# update packages
$ sudo apt upgrade

# remove packages
$ sudo apt uninstall PACKAGE

OpenSUSE, SUSE Linux Enterprise

The SUSE family is managed with Zypper. It is another package manager to manage RPM packages.

# search for a packages
$ zypper search SEARCHTERM

# install a package
$ sudo zypper install PACKAGE

# update packages
$ sudo zypper upgrade

# Uninstall a package
$ sudo zypper remove PACKAGE

Conclusion

That should do it for now and get you started. There is way more that might be interesting to follow up with. Services, permissions and much more could be covered in another article.

I would be interested if you just started with Linux or use it already for years? Also, what was your starting distribution? Please let me know :)