In the last chapter, we became familiar with single-board computers and Raspberry Pi. We also learned the basics of Linux and the Raspberry Pi OS. We learned how to prepare a SD card with the RPi OS and how to boot up a RPi board with the RPi OS. We also learned a few basics of working with the terminal emulator.

As a continuation of the last chapter, we will explore the following concepts in this chapter:

  • Operating system shell

  • Raspberry Pi OS GUI

  • The command prompt

  • Linux filesystem

  • Remotely accessing the RPi

After completing this chapter, we will be very comfortable with the terminal emulator and shell of Linux. We will also be comfortable with the Linux filesystem.

I would like to note one more thing. I am using a RPi 4 B with 4 GB RAM for the demonstrations throughout the book. However, all the demonstrations in this book will work with any RPi board model. And the commands that are not specific to the RPi OS will run on any Debian Linux distribution or derivative. If any command is specific to the RPi OS and not compatible with Debian, then I will mention it in the description.

Operating System Shell

In any operating system, a shell is a user interface for accessing a system's services.

It takes input from the user and executes programs based on that input. When a program finishes execution, the shell displays the program's output.

All the operating systems have shells. An operating system can have multiple shells. A shell can use the Command-Line Interface (CLI) (like the Unix terminal emulator programs) or Graphical User Interface. In this chapter, we will explore both the concepts in detail.

Command-Line Interface (or CLI)–based shells need users to memorize the commands. We will explore a variety of commands throughout this and the remaining chapters of this book. Shell commands can be put together into scripts that can be used to perform a variety of tasks on a Unix-like computer.

Graphical User Interface (or GUI)–based shells are easier to use. Basically these use one of the varieties of the desktop environments for Unix-like operating systems. We can read more about the desktop environments in the article at https://itsfoss.com/best-linux-desktop-environments/.

Raspberry Pi OS GUI

Let us have an overview of the RPi OS GUI. We have a dedicated chapter near the end of this book for exploring a few GUI utilities of the Raspberry Pi OS. In this section, we are just going to have a very brief overview of the GUI of the RPi OS. The Raspberry Pi OS uses the PIXEL desktop which is a customized LXDE (Lightweight X11 Desktop Environment ). Other popular desktop environments for Unix-like operating systems are KDE, GNOME, and XFCE. It is possible to use these with the RPi OS, but for the sake of simplicity, we will stick to the default LXDE for our demonstrations throughout the book.

Let us have an overview of the GUI of the RPi OS. When we boot it up, we can see a desktop like any other Unix-like environment. The desktop has a taskbar where we can see various options (Figure 2-1).

Figure 2-1
figure 1

Raspberry Pi OS Desktop

The Raspberry fruit symbol in the leftmost corner is the RPi OS menu where we can find all the GUI packages for making our life easier. The globe symbol next to that is the shortcut for a web browser. The folders symbol next to that is the shortcut for the File Explorer utility. Then the black icon next to it is the shortcut for the lxterminal which is the default command-line terminal emulator for the RPi OS. We have already used it briefly for changing the networking settings.

On the right-hand side, we can see the VNC server symbol. This is because I am accessing the desktop remotely using a Windows computer. We will learn about it in detail in the later part of this chapter. After that, we see a Bluetooth symbol. We can connect to a Bluetooth device of our choice using this. The next is the WiFi symbol. We can connect to a WiFi network of our choice. After that, we can see the audio meter for adjusting the sound and a clock. On the desktop, the only icon is the Trash, where you can find the recently deleted items, and they can be either recovered or removed permanently from here. If you ever have worked with any GUI-based operating system, you will find all this very familiar.

The Command Prompt

We can access the command prompt by using the terminal emulator, lxterminal. Open the lxterminal window and execute the following command:

echo $SHELL

It will return the following output:

/bin/bash

This is the default shell of the RPi OS. It is known as the Bash shell. The output is the location of the executable file for the program of the Bash shell. The RPi OS has other shells. We can see them with the following command:

ls -la /bin/*sh*

It will return the following output:

pi@raspberrypi:~ $ ls -la /bin/*sh* -rwxr-xr-x 1 root root 925124 Apr 18  2019 /bin/bash -rwxr-xr-x 1 root root  91896 Jan 18  2019 /bin/dash lrwxrwxrwx 1 root root      4 Apr 18  2019 /bin/rbash -> bash lrwxrwxrwx 1 root root      4 May 27 12:35 /bin/sh -> dash

There are four lines in the output. And as we can see, there are four shells, namely, bash, dash, rbash, and sh. rbash and sh are nothing but the symbolic links (represented by the -> symbol in the earlier output) to the bash and dash shells. So the RPi OS has two shells, and Bash is the default shell.

Do not worry too much about these commands as of now. We will learn them in detail in the upcoming chapters.

Updating the RPi OS

In the last chapter, we learned how to get the RPi board up and running with the RPi OS. We had skipped the process to update the RPi OS at the first-time configuration of the RPi. Let us update it from the command prompt now. All the latest packages are updated in the RPi OS repository, and we can update the RPi OS by referring to this repository using the Internet. The following command is used to download package information from all configured sources:

sudo apt-get update -y

This updates the information on the updated versions of packages or their dependencies. After this, we have to run the following command:

sudo apt-get dist-upgrade -y

This command upgrades all the packages and their dependencies and also removes all the obsolete packages. The parameter -y in both the commands means we are entering y whenever the execution prompts for Yes/No.

Finally, update the firmware with the following command:

sudo rpi-update

This is how we update the RPi OS and the firmware on the RPi board.

Linux Filesystem

In this section, we will briefly discuss the Linux filesystem. The Linux filesystem is modeled after the Unix filesystem. We can explore the filesystem using the File Explorer. When we open the File Explorer, it opens the visual view of the folder /home/pi. Folders are also known as directories. Figure 2-2 is a screenshot of the File Explorer showing the /home/pi.

Figure 2-2
figure 2

File Explorer

We can see many folders and files in the /home/pi folder. This folder is the home directory of the user pi. In the topmost part, under the menu bar, we can see an address bar. There, type in the character / and press Enter. This / is the root directory of the filesystem. The filesystems of most of the popular Unix-like operating systems are treelike structures, and the directory / is the root of that tree. Figure 2-3 is a File Explorer view of this directory.

Figure 2-3
figure 3

File Explorer view of the / (root) directory

Here, we can see many directories under the root directory. The following are brief descriptions of the important directories:

  • /bin: The /bin directory has many of the user executable files.

  • /boot: This directory has a bootloader, a kernel executable, and configuration files required to boot a Unix-like OS on a computer. In the RPi OS, the config.txt file has all the boot-related options.

  • /dev: This directory has the device files for all the hardware devices attached to the computer.

  • /etc: This directory contains the local system configuration files for the host computer.

  • /home: This is the home directory storage for user files. Each user has a subdirectory in this directory.

  • /lib: This directory has shared library files that are required to boot the system.

  • /media: Here, all the new storage devices are mounted. For example, when we attach a portable USB drive to the RPi, it will show up here.

  • /mnt: This is a temporary mount point for regular filesystems.

  • /opt: Optional files are located here. An example of optional files is the vendor-supplied programs.

  • /root: This is not the root directory of the (/) filesystem. This is the home directory for the root user.

  • /sbin: These are the system binary files. These are the executable programs used for system administration.

  • /tmp: This is the temporary directory. It is used by the operating system and many programs to store temporary files. Users may also store files temporarily in this location. Note that files stored here may be purged by the OS without any warning.

  • /usr: These are shareable, read-only files, including executable binaries and libraries, man files, and other types of documentation.

  • /var: Variable data files are stored here. Examples are log files, MySQL and other database files, web server data files, email inboxes, and other program-specific files.

Remotely Accessing the RPi

We can remotely access the RPi’s desktop and command prompt. For accessing the command prompt, we have already enabled the remote SSH while configuring the RPi after the OS setup. We can use any SSH client. However, I find the bitwise SSH client the most convenient. We can install it for the Windows OS by downloading it from www.bitvise.com/ssh-client-download. It is free of cost. Once we install it, we open it. We can find it by typing in SSH in the search bar of Microsoft Windows. The bitwise SSH connection window is as shown in Figure 2-4.

Figure 2-4
figure 4

Bitwise SSH connection window

Fill in the details for the host, username, and password (pi and raspberry is the default combination, in case you forgot). Then click the Login button. When we log in to any new host the first time, it shows the message in Figure 2-5.

Figure 2-5
figure 5

Host Key Verification Window

Click the Accept and Save button. This will save the host key of the RPi to the Windows computer, and this message will not be shown again for the same RPi when we make a fresh connection the next time. Once we connect, it will show us the RPi OS command prompt as shown in Figure 2-6.

Figure 2-6
figure 6

RPi OS command window remote access with SSH

It also opens a File Transfer window as shown in Figure 2-7.

Figure 2-7
figure 7

File Transfer Window

We can simply drag and drop files from Windows to RPi and vice versa. On the left, we have the Windows desktop for the current user, and on the right-hand side, we have the home directory for the user pi on the RPi OS.

This is how we can access the command prompt of the RPi OS and transfer files visually. Now, we will see how to remotely access the desktop. The RPi OS comes with the VNC server. We have already enabled the VNC server at the time of configuration after the installation. We just need to install a VNC viewer on our Windows PC. It can be done by downloading it from www.realvnc.com/en/connect/download/viewer/. We can search for it through Windows search by typing in VNC. The window for the application is as shown in Figure 2-8.

Figure 2-8
figure 8

VNC viewer window

In the menu, click FileNew Connection. It opens a new connection window as shown in Figure 2-9.

Figure 2-9
figure 9

Connection details

Fill in the IP address and the name that you want to set for your connection, and click the OK button. It will create an icon corresponding to the connection in the VNC viewer application window. Double-click it to connect, and the window in Figure 2-10 will appear.

Figure 2-10
figure 10

Credentials

Just key in the username and password. Click the checkbox Remember password so we won’t be asked again for the credentials. Finally, click the OK button. It will open a remote desktop window as shown in Figure 2-11.

Figure 2-11
figure 11

Remote desktop with the VNC viewer

Unless you are using very outdated networking equipment, the response is real time and smooth. We can carry out all the GUI-related tasks this way without needing an extra monitor.

So this is how we can access the RPi’s command prompt and desktop remotely.

Summary

In this chapter, we learned the basics of the Linux shell, GUI, and command prompt. We also learned how to update the RPi OS and the firmware with commands. We finally learned how to access the command prompt and the desktop remotely. All these topics are needed to get started with learning the commands of the Linux operating system.

In the next chapter, we will continue our journey of exploring the Linux operating system. We will learn some simple file- and directory-related commands. We will also learn the basics of a few text editors.