Chapter 1: Introduction to the Linux Shell

What is Linux Shell

What is a Shell?

A shell is a program that provides a text-based interface to interact with your operating system. It lets you control your computer by typing commands.

Think of it as the middleman between you and the system’s core (kernel). You type a command like ls, the shell passes it to the system, gets the result, and shows it to you.

Terminal vs Console vs Shell

These terms often get mixed up. Here’s what each means:

TermMeaning
ConsoleOriginally, a physical terminal (keyboard + monitor) directly connected to a computer. Now it often means any system terminal.
TerminalA software window (like GNOME Terminal, Konsole, xterm) that emulates a console. It’s the UI you open to type commands.
ShellThe actual program that interprets your commands (like Bash or Zsh). The terminal runs the shell.

So when you open a terminal → it runs a shell → you type commands into it.

These are the most commonly used shells today:

ShellCommon Use
bash (Bourne Again Shell)Most Linux distributions, shell scripts, system administration
zsh (Z Shell)Preferred by power users and developers (e.g., with Oh My Zsh), macOS default since Catalina
PowerShellCross-platform scripting, DevOps, Windows administration, also used in Linux/WSL environments

Distribution Differences (RHEL vs. Debian)

While the core functionality of shells like Bash remains consistent across Linux distributions, there are subtle differences in package management, default configurations, and typical system administration practices that you’ll encounter. Understanding these distinctions is crucial, especially when moving between different environments:

  • Package Management:
    • RHEL (Red Hat Enterprise Linux) and its derivatives (e.g., CentOS, Fedora): Primarily use yum or dnf for installing, updating, and removing software packages. For instance, to install a package, you’d use sudo dnf install <package_name>.
    • Debian and its derivatives (e.g., Ubuntu, Linux Mint): Primarily use apt (Advanced Package Tool) for package management. The equivalent command to install a package would be sudo apt install <package_name>.
  • Default Tools and Utilities: While many commands are universal, some distributions might include specific utilities by default or have different versions. For instance, network configuration tools or system service management (though systemd is now common across both) might have slight variations in their common usage patterns.
  • File System Layout (Minor Differences): While the fundamental Unix file system hierarchy is largely consistent, you might find minor variations in where certain configuration files or logs are stored between RHEL and Debian-based systems.

These differences primarily affect how you interact with the operating system to perform administrative tasks, rather than how you write and execute commands within the shell itself.

Understanding the Command Prompt ($ and #)

When you open the terminal, you see something like this:

user@hostname:~$

This is called the command prompt. It shows:

  • user → your username
  • hostname → your computer’s name
  • ~ → your current folder (here it means “home folder”)
  • $ → you’re a regular user

What does # mean?

If you’re logged in as the root user (superuser), the prompt changes to:

root@hostname:~#

The # means you have full system control. Be careful — you can delete or change anything.

Shell configuration file

What is ~/.bashrc?

The file ~/.bashrc is a hidden file in your home directory. It runs automatically every time you open a new terminal.

You can use it to:

  • Set environment variables
  • Create command shortcuts (aliases)
  • Customize your prompt
  • Run startup scripts

Example: Set a Custom Variable

Let’s say you often work on a project stored in a long path like:

/home/user/work/projects/myapp/

You can create a shortcut variable in .bashrc:

Step 1: Open .bashrc

nano ~/.bashrc

Step 2: Add a variable at the bottom

export MYAPP="/home/user/work/projects/myapp"

Step 3: Save and reload

source ~/.bashrc

Step 4: Use it in the terminal

cd $MYAPP

Now you can jump to that directory anytime just by typing cd $MYAPP.

Summary

  • A shell interprets commands. The terminal runs the shell.
  • Open the terminal depending on your Linux desktop environment.
  • The shell prompt shows who you are and where you are.
  • $ = normal user, # = root user.