applied linux.

Chapter 2 of 9

Learning the Terminal

Now that you’ve got an instrument, it’s time to practice.

At first, learning finger positions for an instrument may not make much sense; however, the movements become more natural after time spent practicing. The same thing can be said about the terminal interface for Linux and other UNIX-like systems. Over time, your fluency with commands will grow, similar to learning new notes and chords. After struggling through flat notes and mistyped commands, you’ll soon be playing entire pieces and navigating the interface.

This terminology as well as the screen size of 24 x 80 characters is left over from the days of green screen IBM 3270’s that had a display and a keyboard connected to a mainframe over coaxial connections. These were eventually abandoned and replaced with “TN3270” which is a data stream interpreter over telnet. You however are not limited and can open as many terminals (or tty’s, teletypewriters) as you desire.

When you think about the operating system, think of it as being in the center of several concentric circles. In the center, ring 0, you have root, in the first ring you have the kernel space, followed by the System Call Interface which is the boundary between User and Kernel space, finally in ring 3 you have the user space.

LevelLayerDescription
3User SpaceManages user accounts, groups, and file permissions. Controls file read, write, and execute permissions based on users and groups. This is where regular applications and processes run, as well as daemons.
2System Call InterfaceThe boundary between user space and kernel space. Manages requests from user-space programs to interact with the kernel through system calls.
1Kernel SpaceHandles process management, resource allocation, and access control. Enforces permissions based on UID/GID at the system level.
1Linux Security Modules (LSMs)Security-enhancing mechanisms like SELinux, AppArmor, and Capabilities. Adds fine-grained access controls and security policies beyond traditional permissions.
1Filesystem-Level SecurityAdvanced features like ACLs (Access Control Lists) and extended attributes for fine-grained control over file and directory permissions.
0Root PrivilegesThe highest level of access. The root user (UID 0) has full control over the system, bypassing all other permission layers. Root operates in Ring 0 with unrestricted access.

Table: Linux Permission Model Layers (Ring 0 to Ring 3).

Daemons, like other user-space processes in Linux, interact with the kernel primarily through system calls. Although daemons often run with elevated privileges—especially those performing critical system tasks—they still operate in user space (Ring 3) and must communicate with the kernel (which resides in Ring 0) through well-defined, controlled interfaces.

The Linux kernel manages all system resources, including hardware, memory, and networking. However, processes in user space, including daemons, do not have direct access to these resources. Instead, they rely on the kernel to perform privileged operations on their behalf. This is achieved through system calls, which are essentially requests made by user-space programs to the kernel for performing specific tasks, such as reading or writing files, managing memory, or handling network communications.

For example, a network-related daemon like sshd, which listens for incoming SSH connections, needs to interact with the kernel to bind to network ports, handle connections, and manage data transmission. To achieve this, it makes system calls such as socket(), bind(), and listen(). Similarly, file-related daemons like syslogd, which handles logging, rely on system calls like open(), write(), and close() to manage log files.

By using system calls, daemons can safely and efficiently request services from the kernel while maintaining the security boundary between user space and kernel space. This model ensures that even privileged daemons cannot directly manipulate hardware or critical system resources without going through the kernel, thereby enhancing the overall stability and security of the system.


By now, you should have rebooted your new system using the installation media and logged in with the username and password you created during installation.

Next, you’ll need to open the terminal. Here’s how:

  1. Find the Terminal: The terminal icon typically looks like a black box with a $_ symbol. - Click the logo icon in the bottom left corner of your screen, or - Press the Meta or Super key (often labeled as the “Windows” key on modern keyboards).

  2. Search for Terminal: Once the menu opens, type “Terminal” in the search bar and select the terminal app from the results.

  3. Terminal Window: A black or gray box will appear, which is your terminal. This terminal opens your system’s shell automatically, with a flashing cursor at a prompt symbol like #, $, or >. - The $ symbol indicates you’re in user mode. - The # symbol means you’re running as root or an administrator. - The > symbol often indicates a custom prompt.

Now that you’ve opened the terminal, you can start typing commands. To become familiar with the prompt, we’ll practice basic file navigation, configure the network and firewall, and perform an installation of software and update the system.

Listing Files and Directories with ls

The first step in interacting with your filesystem is understanding what’s inside a directory. The ls command is the most basic tool for this. When you type ls in your terminal, it lists the files and directories in your current location. To get more detailed information, such as file permissions, sizes, and modification times, you can use ls -l, which shows each item in a long format.

We’ll then create a file we’ll be working with, file1.txt, using the redirect and echo command. Do this by running echo "Hello, Linux World!" > file1.txt to create a file called file1.txt with the text “Hello, Linux World!” inside. Then, use cat file1.txt to verify its contents.

Redirects and Pipes: Combining Commands

Redirection is an essential feature of Linux. You can redirect the output of one command into a file or pipe the output into another command. Pipes, represented by the | symbol, allow you to take the output of one command and feed it directly into another command.

Exercise 1

Open a terminal, navigate to your home directory using cd ~, and run ls to list all files. Then, try ls -l to see the detailed view. Compare the outputs to understand the difference.

Copying Files with cp

The cp command is used to create a copy of a file or directory. You can specify the source and destination, and Linux will copy the contents. Whether you’re backing up files or organizing your workspace, cp is the go-to tool for duplication.

Exercise 2

In your terminal use cp to copy a file. For example, if you have a file named file1.txt in your directory, try cp file1.txt file1_backup.txt. Then, use ls to verify that the file was copied.

Moving and Renaming Files with mv

Moving and renaming files in Linux is simple with the mv command. While mv is commonly used to relocate a file from one directory to another, it also serves as a way to rename files.

Exercise 3

Move a file from one directory to another. For example, if you have a directory called Documents, move file1_backup.txt there using mv file1_backup.txt ~/Documents/. Then navigate to the Documents directory using cd ~/Documents/ and confirm the move with ls.

Exercise 4

Rename a file by using mv. For instance, if you have file1.txt, rename it to renamed_file.txt by running mv file1.txt renamed_file.txt. Verify the change with ls.

Viewing File Contents with cat, more, and less

When you need to view the contents of a file, Linux provides several tools. The simplest is cat, which displays the entire file at once. For larger files, however, you might want to use more or less, which show files one screenful at a time. less is particularly useful as it allows you to scroll both forward and backward.

Exercise 5

Use cat to display the contents of a file. Try cat renamed_file.txt if you followed the previous exercise. Next, open a longer file with less, such as a system log file (less /var/log/syslog). Use the arrow keys to navigate the file, and press q to exit.

Searching for Files with find

The find command is a powerful search tool for locating files and directories based on criteria such as name, size, or modification date. It can search recursively through directories, making it indispensable when you don’t remember exactly where something is located.

Exercise 6

Search for all text files in your home directory using find ~ -name "*.txt". Try creating a few text files with different names and rerun the command to practice locating them.

Using echo for Displaying and Redirecting Text

The echo command is often used to display messages or output text into files. By default, it prints text to the terminal, but you can also redirect the output into a file. Redirection uses symbols like > to overwrite or >> to append content to a file.

Exercise 7

Combine cat and grep using a pipe to search for specific text inside a file. For instance, if your greeting.txt contains the word “Linux”, try cat greeting.txt | grep "Linux". This will display any lines containing “Linux”.

Editing Files with nano

Linux includes several text editors, and nano is one of the simplest. It’s a terminal-based editor, perfect for making quick edits to files, especially configuration files. It opens with a simple interface, and you can navigate using keyboard shortcuts displayed at the bottom.

Exercise 8

Open the greeting.txt file in nano by running nano greeting.txt. Add some text, save the file with Ctrl + O, and then exit with Ctrl + X. Confirm the changes by running cat greeting.txt.

$ try it — a real Linux shell, running in your browser

Boots a Buildroot Linux kernel client-side with v86, a 32-bit x86 emulator compiled to WebAssembly. Nothing you type leaves this tab. First boot fetches a ~10 MB kernel; it then runs offline.