Understanding the Shell
Chapter 01
When discussing the command line, we are essentially referring to the shell—a program responsible for accepting keyboard commands and executing them through the operating system. Most Linux distributions provide a shell program called bash, developed by the GNU Project. The term "bash" is an acronym for "Bourne Again SHell," highlighting its role as an enhanced successor to the original Unix shell program, sh, authored by Steve Bourne.
Terminal Emulators
When utilising a graphical user interface, an additional program known as a terminal emulator becomes essential for interacting with the shell. Upon exploring our desktop menus, we are likely to discover a suitable option. KDE utilizes konsole, while GNOME employs gnome-terminal, which may appear as "terminal" in the menu. Although several other terminal emulators exist for Linux, their core functionality remains consistent: providing us with access to the shell. Over time, you may develop a personal preference for a particular emulator based on the additional features and customisation it offers.
Embarking on Your Initial Keyboard Input
Now, let's commence our journey by initiating the terminal emulator! Once it opens, we will be greeted with a display resembling the following:
This signifies the presence of a shell prompt, which materialises whenever the shell is prepared to receive input. Although its appearance might exhibit slight variations depending on the distribution, it typically consists of your username@computername, succeeded by the present working directory (we'll delve into this shortly), and concludes with a dollar sign ($).
When the prompt's concluding character is a pound sign (#) instead of a dollar sign, it indicates that the terminal session possesses superuser privileges. This implies that either we are currently logged in as the root user or have opted for a terminal emulator that grants administrative privileges.
Assuming everything is proceeding smoothly thus far, let's experiment with some typing. Enter random gibberish at the prompt as follows:
As the given command lacks coherence, the shell will promptly notify us of its nonsensical nature and provide an opportunity to try again:
Command History
By pressing the up-arrow key, we will observe the reappearance of the previous command weruiohwelh right after the prompt. This convenient feature is known as command history, where most Linux distributions retain the memory of the last 500 commands by default. Conversely, pressing the down-arrow key will cause the previous command to vanish from view.
Cursor Movement
Once more, retrieve the previous command using the up-arrow key. Now, experiment with the left and right-arrow keys. Observe how the cursor can be placed anywhere along the command line, enabling effortless command editing. This flexibility greatly simplifies the process of modifying commands as needed.
A Few Words About Mice And Focus
While the command line primarily relies on the keyboard, incorporating a mouse into your terminal emulator is feasible. The X Window System, the core of the GUI, has a feature enabling a swift copy-and-paste method. By selecting text with a left mouse button hold-and-drag or double-click, it gets copied into an X-maintained buffer. Subsequently, clicking the middle mouse button pastes the text at the cursor's position. Give it a try!
Avoid using Ctrl-c and Ctrl-v for copy and paste within a terminal window; these commands have distinct meanings to the shell, predating Microsoft Windows by many years.
Your graphical desktop environment, likely KDE or GNOME, might mimic Windows with a "click to focus" policy. Unlike the traditional X behavior of "focus follows mouse," where passing the mouse over a window activates it, the "click to focus" policy requires a click to activate a window. However, changing the focus policy to "focus follows mouse" enhances the usefulness of copy and paste. Try it out if possible (note that some desktop environments like Ubuntu's Unity no longer support this feature). Embracing this change might lead to a preference for this setting, typically found in your window manager's configuration program.
Engage in a few Elementary Commands
Having acquired typing skills, let's proceed with experimenting a few straightforward commands. Our initial command is date, which displays the current time and date.
An associated command is cal which, by default, presents a calendar showcasing the current month.
To retrieve the current available disk space on your disk drives, enter the command df:
Similarly, to showcase the available memory, input the free command.
Concluding a Terminal Session
To terminate a terminal session, we have two options: either close the terminal emulator window or input the exit command at the shell prompt:
Summary
As we embark on our expedition, we acquaint ourselves with the shell and encounter the command line for the very first time. We learn the procedures for initiating and terminating a terminal session, alongside exploring the execution of basic commands and engaging in minor command line editing. Surprisingly, the experience wasn't as daunting as anticipated, was it?
Last updated