The Shell: Your Superpower
Why This Matters
Imagine this: a web server is down, hundreds of users are affected, and you need to find the problem and fix it -- fast. You SSH into the server. There is no graphical interface. No mouse. No menus. Just a blinking cursor. The only tool you have is the shell.
In this moment, the shell is either your greatest asset or your greatest obstacle. If you know your way around it, you can diagnose the problem in seconds: check running processes, read log files, restart services, inspect network connections -- all without leaving the keyboard. If you do not, you are helpless.
The shell is the single most important skill in this book. Every chapter after this one assumes you are comfortable typing commands, reading output, and navigating the filesystem. Master this chapter, and everything else falls into place.
Try This Right Now
Open your Linux terminal (whether it is WSL2, a VM, SSH to a server, or a native Linux desktop) and type:
$ echo "I am $(whoami) on $(hostname), running $(uname -s) kernel $(uname -r)"
You should see something like:
I am yourname on ubuntu-lab, running Linux kernel 6.1.0-18-amd64
You just used four commands (echo, whoami, hostname, uname) combined into a single line using command substitution ($(...) runs a command and inserts its output). This is the kind of thing the shell makes effortless.
Terminal vs Shell vs Console: Clearing the Confusion
These three terms are used loosely, but they mean different things.
┌─────────────────────────────────────────────────────┐
│ │
│ TERMINAL EMULATOR │
│ ┌─────────────────────────────────────────────────┐ │
│ │ │ │
│ │ The window that displays text. It handles │ │
│ │ fonts, colors, scrolling, and keyboard input. │ │
│ │ │ │
│ │ Examples: GNOME Terminal, Konsole, Alacritty, │ │
│ │ iTerm2, Windows Terminal, xterm │ │
│ │ │ │
│ │ ┌──────────────────────────────────────────┐ │ │
│ │ │ │ │ │
│ │ │ SHELL │ │ │
│ │ │ │ │ │
│ │ │ The program that interprets your │ │ │
│ │ │ commands. It reads what you type, │ │ │
│ │ │ executes programs, and shows output. │ │ │
│ │ │ │ │ │
│ │ │ Examples: bash, zsh, fish, sh, dash │ │ │
│ │ │ │ │ │
│ │ └──────────────────────────────────────────┘ │ │
│ │ │ │
│ └─────────────────────────────────────────────────┘ │
│ │
│ CONSOLE │
│ The physical or virtual text interface │
│ (e.g., the screen when no GUI is running, │
│ or Ctrl+Alt+F1 through F6 on Linux) │
│ │
└─────────────────────────────────────────────────────┘
- Terminal emulator: the application that provides the window. It is just a container.
- Shell: the program running inside the terminal that actually interprets your commands.
- Console: historically the physical terminal attached to a machine. Today, it usually refers to the virtual terminals you can switch to with Ctrl+Alt+F1 through F6 on a Linux system.
When you open "Terminal" on your Linux desktop, you are launching a terminal emulator that starts a shell (usually Bash) inside it.
Which Shell Are You Using?
# What shell is running right now?
$ echo $SHELL
/bin/bash
# What version?
$ bash --version
GNU bash, version 5.2.15(1)-release (x86_64-pc-linux-gnu)
# What shells are available on this system?
$ cat /etc/shells
/bin/sh
/bin/bash
/usr/bin/bash
/bin/zsh
/usr/bin/zsh
/bin/dash
The Major Shells
Bash (Bourne Again Shell) -- the default on most Linux distributions. This is what we use throughout this book. It is the lingua franca of Linux.
Zsh (Z Shell) -- the default on macOS since Catalina. Compatible with Bash but adds features like better tab completion, spelling correction, and plugin frameworks (Oh My Zsh). Popular on developer workstations.
Fish (Friendly Interactive Shell) -- designed for usability. Features autosuggestions, syntax highlighting out of the box, and a web-based configuration interface. Not POSIX-compatible, so scripts written for Bash may not work in Fish.
Dash -- a minimal POSIX-compliant shell. Used as /bin/sh on Debian/Ubuntu for speed. Not meant for interactive use.
sh (Bourne Shell) -- the original Unix shell. On modern Linux, /bin/sh is usually a symlink to dash or bash.
For this book, use Bash. It is everywhere, and understanding Bash gives you the foundation to learn any other shell quickly.
Think About It: If Bash is the default shell on most Linux distributions, why do alternative shells like Zsh and Fish exist? What might they offer that Bash does not?
Anatomy of a Command
Every shell command follows the same basic structure:
command [options] [arguments]
│ │ │
│ │ └── What to act on (files, strings, etc.)
│ │
│ └── Modify the command's behavior (flags/switches)
│
└── The program to run
Examples:
ls # command only (no options, no arguments)
ls -l # command + option
ls -l /home # command + option + argument
ls -la /home /tmp # command + multiple options + multiple arguments
cp -r /source /destination # command + option + two arguments
Options: Short and Long Form
Most commands support both short (single dash, single letter) and long (double dash, word) options:
ls -a # short form: show all files (including hidden)
ls --all # long form: same thing
ls -l # short form: long listing format
ls --format=long # long form: same thing
ls -la # short forms can be combined: -l + -a
ls -l -a # equivalent: separate short options
ls --all --format=long # long forms cannot be combined
The -- Convention
A double dash by itself (--) means "end of options, everything after this is an argument":
# What if you have a file named "-l" and want to delete it?
$ rm -l # ERROR: rm interprets -l as an option
$ rm -- -l # CORRECT: -- tells rm that -l is a filename
Your First Commands
Let us work through the essential commands, one at a time. Type each one.
pwd -- Where Am I?
$ pwd
/home/yourname
pwd stands for Print Working Directory. It tells you your current location in the filesystem. You always have a current location, and it matters because relative paths are relative to this location.
ls -- What Is Here?
# List contents of current directory
$ ls
Desktop Documents Downloads Music Pictures
# Long format: permissions, owner, size, date
$ ls -l
total 20
drwxr-xr-x 2 yourname yourname 4096 Jan 15 10:30 Desktop
drwxr-xr-x 2 yourname yourname 4096 Jan 15 10:30 Documents
drwxr-xr-x 2 yourname yourname 4096 Jan 15 10:30 Downloads
drwxr-xr-x 2 yourname yourname 4096 Jan 15 10:30 Music
drwxr-xr-x 2 yourname yourname 4096 Jan 15 10:30 Pictures
# Show hidden files (files starting with .)
$ ls -a
. .. .bash_history .bashrc .profile Desktop Documents ...
# Combine: long format + hidden + human-readable sizes
$ ls -lah
total 44K
drwxr-xr-x 7 yourname yourname 4.0K Jan 15 10:30 .
drwxr-xr-x 3 root root 4.0K Jan 14 09:00 ..
-rw------- 1 yourname yourname 256 Jan 15 10:45 .bash_history
-rw-r--r-- 1 yourname yourname 220 Jan 14 09:00 .bash_logout
-rw-r--r-- 1 yourname yourname 3.5K Jan 14 09:00 .bashrc
drwxr-xr-x 2 yourname yourname 4.0K Jan 15 10:30 Desktop
...
# List a specific directory
$ ls -l /etc/
Key flags to remember:
-l-- long format (permissions, owner, size, date)-a-- all files, including hidden (dotfiles)-h-- human-readable sizes (K, M, G instead of bytes)-t-- sort by modification time (newest first)-r-- reverse sort order-R-- recursive (list subdirectories too)
cd -- Move Around
# Go to a directory
$ cd /var/log
$ pwd
/var/log
# Go to your home directory (three equivalent ways)
$ cd
$ cd ~
$ cd $HOME
# Go to the previous directory
$ cd -
/var/log
# Go up one level
$ cd ..
$ pwd
/var
# Go up two levels
$ cd ../..
$ pwd
/
Important concepts:
.means "current directory"..means "parent directory"~means "home directory" (/home/yourname)-means "previous directory" (where you just were)
cat -- Read File Contents
# Display a file's contents
$ cat /etc/hostname
ubuntu-lab
# Display with line numbers
$ cat -n /etc/passwd | head -5
1 root:x:0:0:root:/root:/bin/bash
2 daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
3 bin:x:2:2:bin:/bin:/usr/sbin/nologin
4 sys:x:3:3:sys:/dev:/usr/sbin/nologin
5 sync:x:4:65534:sync:/bin:/bin/sync
cat stands for "concatenate." Its original purpose was to concatenate multiple files, but it is most commonly used to display a single file.
Think About It:
catdumps the entire file to the screen. What happens if the file is thousands of lines long? What might be a better tool for reading long files?
echo -- Print Text
# Print a simple message
$ echo "Hello, Linux!"
Hello, Linux!
# Print the value of a variable
$ echo $HOME
/home/yourname
$ echo "My shell is $SHELL"
My shell is /bin/bash
# Print without a trailing newline
$ echo -n "no newline here"
no newline here$
# Print with escape characters
$ echo -e "Line one\nLine two\nLine three"
Line one
Line two
Line three
echo is the simplest way to produce output. You will use it constantly in scripts and one-liners.
man -- The Manual Pages
$ man ls
This opens the manual page for ls. The man page tells you:
- What the command does
- Every option and flag
- Examples (sometimes)
- Related commands
Navigating man pages:
Spaceorf-- next pageb-- previous page/pattern-- search for "pattern"n-- next search resultN-- previous search resultq-- quit
Man page sections:
# Man pages are organized into sections
$ man 1 ls # Section 1: User commands
$ man 5 passwd # Section 5: File formats (/etc/passwd format)
$ man 8 mount # Section 8: System administration commands
| Section | Contents |
|---|---|
| 1 | User commands (ls, cp, grep) |
| 2 | System calls (open, read, fork) |
| 3 | Library functions (printf, malloc) |
| 4 | Special files (/dev/*) |
| 5 | File formats (/etc/passwd, /etc/fstab) |
| 6 | Games |
| 7 | Miscellaneous (protocols, conventions) |
| 8 | System administration commands (mount, iptables) |
Getting Help: Three Methods
You will need help constantly. That is normal. Here are three ways to get it.
Method 1: man pages (comprehensive)
$ man grep # full manual
$ man -k "copy files" # search man pages by keyword
Method 2: --help flag (quick reference)
$ ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
...
Almost every command supports --help. The output is shorter than a man page and usually sufficient for quick questions.
Method 3: info pages (detailed, GNU-style)
$ info coreutils # detailed GNU documentation
info pages are more detailed than man pages for GNU tools but use a different navigation scheme. Most people prefer man pages.
Which to Use?
- Quick question ("What flag makes ls sort by size?"):
ls --help | grep size - Learning a new command:
man command - Deep reference:
info commandor the online documentation
Tab Completion: Your Fingers Will Thank You
Tab completion is one of the most important productivity features of the shell. Press Tab to auto-complete commands, filenames, and paths.
Hands-On: Try Tab Completion
# Type "cd /e" then press Tab
$ cd /e<TAB>
$ cd /etc/ # auto-completed!
# Type "cd /etc/sys" then press Tab
$ cd /etc/sys<TAB>
$ cd /etc/sysctl.d/ # if only one match, it completes
# Type "cd /etc/s" then press Tab twice
$ cd /etc/s<TAB><TAB>
security/ shadow shells skel/ ssh/ ssl/ subgid subuid sudoers sudoers.d/ sysctl.d/ systemd/
# Multiple matches! Shows all possibilities
# Type "cat /etc/hos" then press Tab
$ cat /etc/hos<TAB>
$ cat /etc/hostname # completed!
# Tab also works for commands
$ sys<TAB><TAB>
systemctl systemd-analyze systemd-cat ...
Rules of tab completion:
- One match: auto-completes immediately
- Multiple matches: press Tab twice to see all options
- No matches: nothing happens (no beep, no output)
In Bash, install bash-completion for even better tab completion (it can complete package names, git branches, systemctl units, and more):
# Debian/Ubuntu
$ sudo apt install bash-completion
# Fedora/RHEL
$ sudo dnf install bash-completion
# Arch
$ sudo pacman -S bash-completion
Distro Note: Most distributions install
bash-completionby default. If tab completion for commands likesystemctlandgitalready works for subcommands and arguments, you already have it.
Command History: The Shell Remembers
The shell keeps a history of every command you type. This is enormously useful.
Basic History Usage
# Show recent commands
$ history
1 ls -la
2 cd /etc
3 cat hostname
4 ping google.com
5 sudo apt update
...
# Show last 10 commands
$ history 10
# Re-run command number 42
$ !42
# Re-run the last command
$ !!
# Re-run the last command that started with "sudo"
$ !sudo
# Search history interactively: press Ctrl+R, then type
$ (press Ctrl+R)
(reverse-i-search)`ping': ping -c 3 google.com
# Press Enter to run it, or Ctrl+R again for the next match
History Configuration
# Where is history stored?
$ echo $HISTFILE
/home/yourname/.bash_history
# How many commands are kept?
$ echo $HISTSIZE
1000
# You can increase these in ~/.bashrc:
# HISTSIZE=10000
# HISTFILESIZE=20000
Essential Keyboard Shortcuts
These work in Bash and most other shells:
┌───────────────────────────────────────────────────┐
│ Navigation │
│ Ctrl+A Move cursor to beginning of line │
│ Ctrl+E Move cursor to end of line │
│ Alt+B Move back one word │
│ Alt+F Move forward one word │
│ Ctrl+← Move back one word (some terminals) │
│ Ctrl+→ Move forward one word │
│ │
│ Editing │
│ Ctrl+U Delete from cursor to beginning │
│ Ctrl+K Delete from cursor to end │
│ Ctrl+W Delete the word before cursor │
│ Alt+D Delete the word after cursor │
│ Ctrl+Y Paste what was last deleted (yank) │
│ │
│ History │
│ Ctrl+R Reverse search history │
│ Ctrl+P Previous command (same as Up arrow) │
│ Ctrl+N Next command (same as Down arrow) │
│ ↑ / ↓ Navigate through history │
│ │
│ Control │
│ Ctrl+C Cancel current command │
│ Ctrl+D Exit shell (or signal end of input) │
│ Ctrl+L Clear the screen (same as `clear`) │
│ Ctrl+Z Suspend current process (background) │
│ │
└───────────────────────────────────────────────────┘
Practice these until they are muscle memory. The difference between a beginner and an experienced Linux user often comes down to how fluently they navigate the command line.
Environment Variables
Environment variables are named values that the shell and programs use for configuration. They are a fundamental part of how Linux works.
Viewing Environment Variables
# See all environment variables
$ env
HOME=/home/yourname
USER=yourname
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
LANG=en_US.UTF-8
TERM=xterm-256color
...
# See a specific variable
$ echo $HOME
/home/yourname
$ echo $USER
yourname
$ echo $SHELL
/bin/bash
Setting Variables
# Set a variable (no spaces around =)
$ GREETING="Hello, Linux"
$ echo $GREETING
Hello, Linux
# This variable exists only in the current shell
# To make it available to child processes, export it:
$ export GREETING="Hello, Linux"
# Set and export in one step
$ export MY_APP_PORT=8080
$ echo $MY_APP_PORT
8080
Warning: There are no spaces around the
=sign.NAME=valueworks.NAME = valuefails with a confusing error (the shell tries to runNAMEas a command with=andvalueas arguments).
Important Environment Variables
| Variable | Purpose | Example Value |
|---|---|---|
HOME | Your home directory | /home/yourname |
USER | Current username | yourname |
SHELL | Default shell | /bin/bash |
PATH | Where to find commands | /usr/local/bin:/usr/bin:/bin |
PWD | Current working directory | /home/yourname |
EDITOR | Default text editor | vim or nano |
LANG | Language/locale setting | en_US.UTF-8 |
TERM | Terminal type | xterm-256color |
HOSTNAME | Machine name | ubuntu-lab |
PATH: How the Shell Finds Commands
When you type ls, how does the shell know where the ls program is? The answer is the PATH variable.
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PATH is a colon-separated list of directories. When you type a command, the shell searches these directories in order, left to right, looking for an executable file with that name.
You type: ls
Shell searches:
/usr/local/sbin/ls -- not found
/usr/local/bin/ls -- not found
/usr/sbin/ls -- not found
/usr/bin/ls -- FOUND! Runs /usr/bin/ls
Finding Where a Command Lives
# which: shows the path to the command that would run
$ which ls
/usr/bin/ls
$ which python3
/usr/bin/python3
# type: shows more detail (aliases, builtins, etc.)
$ type ls
ls is aliased to `ls --color=auto'
$ type cd
cd is a shell builtin
$ type python3
python3 is /usr/bin/python3
# whereis: finds the binary, source, and man page
$ whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz
Modifying PATH
# Add a directory to PATH (temporary, current session only)
$ export PATH="$HOME/bin:$PATH"
$ echo $PATH
/home/yourname/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# To make it permanent, add the export line to ~/.bashrc:
$ echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
Think About It: What happens if you have two different programs both named
python3, one in/usr/bin/and one in/usr/local/bin/? Which one runs when you typepython3? How would you change which one runs?
Hands-On: Putting It All Together
Let us chain together everything you have learned in a real scenario.
Scenario: Investigate an Unknown Linux System
You have just SSH'd into a server you have never seen before. Gather information:
# Who am I?
$ whoami
yourname
# What machine is this?
$ hostname
prod-web-03
# What distribution?
$ cat /etc/os-release | head -2
PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
# What kernel?
$ uname -r
5.15.0-91-generic
# How long has it been running?
$ uptime
14:32:07 up 127 days, 3:21, 1 user, load average: 0.45, 0.38, 0.35
# How much memory?
$ free -h
total used free shared buff/cache available
Mem: 3.8Gi 2.1Gi 312Mi 128Mi 1.4Gi 1.3Gi
Swap: 2.0Gi 128Mi 1.9Gi
# How much disk space?
$ df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 32G 15G 69% /
# What is running? (top 5 CPU consumers)
$ ps aux --sort=-%cpu | head -6
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
www-data 1234 12.3 5.2 512000 201000 ? Sl Jan01 245:32 nginx: worker
mysql 5678 8.7 15.3 1024000 590000 ? Sl Jan01 170:45 /usr/sbin/mysqld
root 9012 1.2 0.5 65000 19000 ? Ss Jan01 23:10 /usr/sbin/sshd
...
# What ports are open?
$ ss -tlnp
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 511 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=1233))
LISTEN 0 511 0.0.0.0:443 0.0.0.0:* users:(("nginx",pid=1233))
LISTEN 0 151 127.0.0.1:3306 0.0.0.0:* users:(("mysqld",pid=5678))
LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=9012))
In under a minute, using only the commands from this chapter, you have determined that this is an Ubuntu web server running Nginx and MySQL, with 69% disk usage (might need attention), and it has been up for 127 days. This is the power of the shell.
Debug This
You are trying to run a program you just downloaded, but the shell cannot find it:
$ my-tool --version
bash: my-tool: command not found
$ ls ~/downloads/my-tool
/home/yourname/downloads/my-tool
The file exists. Why can the shell not find it? Fix it.
Click to see the diagnosis
Problem 1: The directory is not in PATH.
The shell only looks in directories listed in $PATH. ~/downloads/ is not in PATH.
Fix options:
# Option A: Run with full path
$ ~/downloads/my-tool --version
# Option B: Run with relative path
$ ./downloads/my-tool --version # if you are in ~
# Option C: Add the directory to PATH
$ export PATH="$HOME/downloads:$PATH"
$ my-tool --version
Problem 2: The file might not be executable.
$ ls -l ~/downloads/my-tool
-rw-r--r-- 1 yourname yourname 102400 Jan 15 10:00 my-tool
No x in the permissions. Fix:
$ chmod +x ~/downloads/my-tool
$ ~/downloads/my-tool --version
Best practice: Move custom tools to ~/bin/ or /usr/local/bin/ and make sure those directories are in your PATH.
The Shell Startup Files
When Bash starts, it reads configuration files that set up your environment. Understanding which files are read and when is important.
Login Shell vs Non-Login Shell
┌─────────────────────────────────────┐
│ Login Shell │
│ (SSH, console login, su -) │
│ │
│ Reads: │
│ 1. /etc/profile │
│ 2. ~/.bash_profile │
│ (or ~/.bash_login │
│ or ~/.profile) │
│ │
├─────────────────────────────────────┤
│ Non-Login (Interactive) Shell │
│ (opening a new terminal window) │
│ │
│ Reads: │
│ 1. /etc/bash.bashrc (Debian) │
│ /etc/bashrc (RHEL) │
│ 2. ~/.bashrc │
│ │
└─────────────────────────────────────┘
In practice, most people put their customizations in ~/.bashrc because ~/.bash_profile typically sources ~/.bashrc anyway. Check yours:
$ cat ~/.bash_profile
# If this file exists, it often contains:
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
What Goes in ~/.bashrc?
# Aliases (shortcuts)
alias ll='ls -lah'
alias la='ls -A'
alias ..='cd ..'
alias ...='cd ../..'
# Custom PATH
export PATH="$HOME/bin:$PATH"
# Default editor
export EDITOR=vim
# History settings
HISTSIZE=10000
HISTFILESIZE=20000
# Custom prompt (covered more in Chapter 18)
PS1='\u@\h:\w\$ '
After editing ~/.bashrc, reload it:
$ source ~/.bashrc
# or equivalently
$ . ~/.bashrc
Distro Note: On Debian/Ubuntu, the system-wide bashrc is
/etc/bash.bashrc. On Fedora/RHEL, it is/etc/bashrc. Both serve the same purpose.
Combining Commands
The shell has several ways to combine commands. Here is a quick preview (Chapter 18 goes deeper):
# Run commands sequentially (regardless of success/failure)
$ command1 ; command2
# Run command2 only if command1 succeeds
$ command1 && command2
# Run command2 only if command1 fails
$ command1 || command2
# Pipe: send output of command1 as input to command2
$ command1 | command2
# Examples:
$ mkdir mydir && cd mydir # create dir, then enter it
$ sudo apt update && sudo apt upgrade -y # update, then upgrade
$ cat /etc/passwd | grep yourname # find your line in passwd
$ ls /nonexistent || echo "Directory not found" # handle failure
What Just Happened?
┌─────────────────────────────────────────────────────┐
│ │
│ In this chapter, you learned: │
│ │
│ - The terminal is the window. The shell is the │
│ program inside it. Bash is the default shell. │
│ │
│ - Command anatomy: command [options] [arguments]. │
│ Options modify behavior, arguments specify │
│ targets. │
│ │
│ - Essential commands: pwd, ls, cd, cat, echo, man. │
│ These are your daily tools. │
│ │
│ - Tab completion saves keystrokes and prevents │
│ typos. Use it relentlessly. │
│ │
│ - Command history (Ctrl+R, !!, history) lets you │
│ reuse and search past commands. │
│ │
│ - Environment variables (HOME, USER, PATH, SHELL) │
│ configure the shell and programs. │
│ │
│ - PATH tells the shell where to find commands. │
│ Modify it to add custom tool locations. │
│ │
│ - Getting help: man, --help, info. man is your │
│ primary reference. │
│ │
│ - Keyboard shortcuts (Ctrl+A, Ctrl+E, Ctrl+R, │
│ Ctrl+C, Ctrl+L) make you fast. │
│ │
│ - ~/.bashrc is where you customize your shell. │
│ │
│ - Commands can be combined with ;, &&, ||, and |. │
│ │
└─────────────────────────────────────────────────────┘
Try This
Exercises
-
Navigation exercise: Starting from your home directory, use
cdandlsto explore these directories:/etc,/var/log,/usr/bin,/tmp,/proc. For each, uselsto see what is inside andpwdto confirm your location. Return home withcd(no arguments). -
man page exercise: Read the man page for
ls(man ls). Find the option that sorts files by size. Find the option that shows file sizes in human-readable format. Runlswith both options on/usr/bin. -
History exercise: Use
historyto find a command you ran earlier. Re-run it using!number. Practice usingCtrl+Rto search your history for the word "ls". -
PATH exercise: Run
echo $PATHand identify each directory listed. Uselsto see what is in/usr/local/bin. How many executables are in/usr/bin? (Hint:ls /usr/bin | wc -l) -
Variable exercise: Set a variable
MY_NAMEto your name. Echo it. Export it. Start a new Bash session (bash) and verify the variable is still set. Exit the sub-shell (exit). Now try withoutexport-- what happens in the sub-shell? -
Help exercise: For each of these commands, find out what they do using ONLY
manor--help:wc,sort,head,tail,touch. Write a one-sentence description of each. -
Keyboard shortcuts exercise: Type a long command (do not press Enter). Practice: move to the beginning with
Ctrl+A, move to the end withCtrl+E, delete the entire line withCtrl+U, bring it back withCtrl+Y. Clear the screen withCtrl+L.
Bonus Challenge
Customize your ~/.bashrc with at least three aliases that will save you time. For example:
alias update='sudo apt update && sudo apt upgrade -y'
alias ports='ss -tlnp'
alias myip='curl -s ifconfig.me && echo'
Source your .bashrc and test each alias. Think about what commands you type most often and create aliases for them.
What's Next
You can navigate, list files, read file contents, get help, and customize your shell. In Chapter 5, we go deeper into the filesystem -- the hierarchy of directories that organizes everything in Linux, and the profound idea that in Linux, everything is a file.