Computer Science Programming By Language Bash/Shell scripting is the practice of writing programs for a command-line interpreter, or "shell," to automate tasks and manage system operations. As one of the most common and powerful shells, Bash (Bourne-Again SHell) allows users to create scripts—sequences of commands stored in a file—that can manipulate files, execute other programs, configure system environments, and orchestrate complex data-processing pipelines. This form of scripting is a fundamental skill for developers, system administrators, and data scientists working in Unix-like environments (such as Linux and macOS), enabling them to create efficient, repeatable workflows directly from the terminal.
1.1.
Understanding the Command Line Interface
1.1.1.
Definition and Purpose of the Shell
1.1.2.
Shell as a Command Interpreter
1.1.3.
Interactive vs Non-interactive Shells
1.1.4.
Login vs Non-login Shells
1.1.5.
Common Shell Types
1.1.5.1. sh (Bourne Shell)
1.1.5.2. bash (Bourne-Again Shell)
1.1.5.6. tcsh (TENEX C Shell)
1.1.5.7. fish (Friendly Interactive Shell)
1.1.6.
The Role of the Terminal Emulator
1.1.6.1. Terminal Emulators vs Virtual Consoles
1.1.6.2. Popular Terminal Emulators
1.1.6.2.4. Windows Terminal
1.1.6.3. Terminal Settings and Customization
1.1.6.3.2. Font Configuration
1.2.
Basic Shell Navigation and Commands
1.2.1.
Navigating the Filesystem
1.2.1.1. Understanding the Filesystem Hierarchy
1.2.1.1.1. Root Directory (/)
1.2.1.1.2. Home Directories
1.2.1.1.3. System Directories
1.2.1.2. Absolute vs Relative Paths
1.2.1.3. pwd (Print Working Directory)
1.2.1.4. cd (Change Directory)
1.2.1.4.1. Changing to Home Directory
1.2.1.4.2. Using cd - to Switch Directories
1.2.1.4.3. Using cd .. for Parent Directory
1.2.1.4.4. Using CDPATH Environment Variable
1.2.1.5. ls (List Directory Contents)
1.2.1.5.2. Listing Hidden Files (-a)
1.2.1.5.3. Listing with Details (-l)
1.2.1.5.4. Human-readable Sizes (-h)
1.2.1.5.5. Recursive Listing (-R)
1.2.1.5.6. Sorting Options
1.2.1.5.6.3. Reverse Order (-r)
1.2.1.5.7. Color Output (--color)
1.2.2.
Manipulating Files and Directories
1.2.2.1. touch (Create Empty Files)
1.2.2.1.1. Creating Multiple Files
1.2.2.1.2. Updating Timestamps
1.2.2.1.3. Setting Specific Times
1.2.2.2. mkdir (Create Directories)
1.2.2.2.1. Creating Parent Directories (-p)
1.2.2.2.2. Setting Permissions (-m)
1.2.2.3. cp (Copy Files and Directories)
1.2.2.3.1. Copying Single Files
1.2.2.3.2. Copying Multiple Files
1.2.2.3.3. Copying Recursively (-r)
1.2.2.3.4. Preserving Attributes (-a)
1.2.2.3.5. Interactive Mode (-i)
1.2.2.3.6. Verbose Mode (-v)
1.2.2.4. mv (Move and Rename Files and Directories)
1.2.2.4.3. Interactive Mode (-i)
1.2.2.4.4. Verbose Mode (-v)
1.2.2.5. rm (Remove Files)
1.2.2.5.1. Removing Single Files
1.2.2.5.2. Removing Multiple Files
1.2.2.5.3. Removing Directories (-r)
1.2.2.5.4. Forcing Removal (-f)
1.2.2.5.5. Interactive Mode (-i)
1.2.2.5.6. Verbose Mode (-v)
1.2.2.6. rmdir (Remove Empty Directories)
1.2.2.7. find (Search for Files and Directories)
1.2.3.
Viewing File Contents
1.2.3.1. cat (Concatenate and Display Files)
1.2.3.1.1. Displaying Single Files
1.2.3.1.2. Concatenating Multiple Files
1.2.3.1.3. Numbering Lines (-n)
1.2.3.2. less (Paged Viewing)
1.2.3.2.1. Navigation Commands
1.2.3.2.2. Search Functions
1.2.3.2.3. Configuration Options
1.2.3.3. more (Basic Paging)
1.2.3.4. head (View Beginning of Files)
1.2.3.4.1. Default Behavior
1.2.3.4.2. Specifying Number of Lines (-n)
1.2.3.5. tail (View End of Files)
1.2.3.5.1. Default Behavior
1.2.3.5.2. Specifying Number of Lines (-n)
1.2.3.5.3. Following File Growth (-f)
1.2.3.5.4. Following by Name (--follow=name)
1.2.4.
Getting Help and Documentation
1.2.4.1. man (Manual Pages)
1.2.4.1.1. Section Numbers
1.2.4.1.2. Navigation in man Pages
1.2.4.1.3. Searching man Pages
1.2.4.2. info (Info Documents)
1.2.4.3. help (Built-in Help)
1.2.4.4. Command --help Option
1.2.4.5. which (Locate Commands)
1.2.4.6. whereis (Locate Binary, Source, and Manual)
1.2.4.7. type (Display Command Type)
1.3.
Your First Shell Script
1.3.1.
The Shebang Line
1.3.1.1. Purpose and Syntax
1.3.1.2. Common Shebang Lines
1.3.1.2.2. #!/usr/bin/env bash
1.3.1.3. Choosing the Right Shebang
1.3.2.
Creating and Saving a Script File
1.3.2.1. Choosing a Text Editor
1.3.2.2. File Naming Conventions
1.3.2.2.1. Descriptive Names
1.3.2.2.2. Avoiding Spaces
1.3.2.2.3. Using Underscores or Hyphens
1.3.2.3.2. No Extension Approach
1.3.3.
Setting Execute Permissions
1.3.3.1. Understanding File Permissions
1.3.3.1.1. Read, Write, Execute
1.3.3.1.2. Owner, Group, Other
1.3.3.1.3. Numeric Notation
1.3.3.1.4. Symbolic Notation
1.3.4.
Running a Script
1.3.4.1. Executing with Relative Path
1.3.4.2. Executing with Absolute Path
1.3.4.3. Running with bash script.sh
1.3.4.4. Adding Script Directory to PATH
1.3.4.5. Common Execution Errors
1.3.4.5.1. Permission Denied
1.3.4.5.2. Command Not Found
1.3.4.5.3. Bad Interpreter