Linux commands, Bash scripts, and the things I'll learn along the way.
I'm a BS Software Engineering student at UBIT, University of Karachi. I started this repo while learning Linux commands and Bash scripting for my Operating Systems lab. It holds my notes, example scripts, and exercises for practice and revision.
I want to keep going after the course and build scripts that help with everyday work. If you're taking an OS course or just curious about Linux, come learn with me. You can start from zero.
Latest published Bash chapter: Bash 04: Operators and Expressions
At a glance: 8 Linux command chapters · 4 Bash chapters · 15 chapter scripts · 11 practice scripts.
New to Linux? Start here: terminal and editor setup → Follow the Ubuntu setup steps, install Git, and get your workspace ready for the examples below.
For my final Operating Systems course project, I built DeployLatch, a Bash tool that deploys a Java service on Ubuntu, checks its health and version, and attempts to restore the previous working release if an update fails.
It connects the file paths, permissions, Bash, and exit statuses practised here to my Java backend work. It also took me into symbolic links, systemd services, and deployment locking—topics I'm still building towards in these notes.
See the deployment demo · Read the deployment script
The route I have in mind is commands → Bash → Linux systems → automation → developer tools. The linked chapters are published notes; the separate practice exercises below sometimes go ahead of the lessons. The roadmap shows topics I want to write about next.
First time here? Start with Navigation and Paths. Already comfortable moving around the terminal? Try Shell and Script Basics.
📂 Linux commands · 8 chapters available
| Chapter | What's inside |
|---|---|
| 01 · Navigation and paths | pwd, ls, cd, paths, hidden files, quoting names, and a guided practice route. |
| 02 · Files and directories | mkdir, touch, file, stat, tree, timestamps, and a tiny project to build. |
| 03 · Viewing file content | cat, head, tail, less, more, sample files, and a live log experiment. |
| 04 · Copying, moving, and deleting | cp, mv, rm, rmdir, destination paths, overwrite prompts, and a lab session to pack up. |
| 05 · Searching and finding | grep, find, patterns, file searches, and a folder of clues to investigate. |
| 06 · Text processing | wc, cut, sort, uniq, tr, sed, awk, and a small study report. |
| 07 · Redirection and pipes | Input, output, errors, >, >>, <, pipes, tee, and a review report to save. |
| 08 · Permissions and ownership | rwx, chmod, numeric modes, directory access, chown, chgrp, and a lab folder to configure. |
🐚 Bash scripting · 4 published chapters
| Chapter | What's inside | A script to open |
|---|---|---|
| 01 · Shell and script basics | Shells, shebangs, execution order, syntax checks, and a lab check-in script to write. | hello.sh · sequential-commands.sh |
| 02 · Variables and expansion | Variables, quoting, command substitution, and arithmetic expansion. | quoting.sh |
| 03 · Input and output | echo, printf, read, and prompts. |
formatted-output.sh |
| 04 · Operators and expressions | Arithmetic, comparisons, logic, exit status, and command chaining. | numeric-comparisons.sh |
Beyond the chapters: Browse 11 Bash practice exercises covering basics, conditions, loops, and arrays. These are standalone scripts; full lesson notes on conditions, loops, and arrays are still to come.
🧪 Bash practice · topics and example scripts
| Practice folder | What I'm practising | Examples |
|---|---|---|
| Basics · 4 scripts | Reports, input, arithmetic, percentages, and conditions. | System report · Percentage and pass/fail |
| Loops · 3 scripts | Input validation, conditions, iteration, and menu choices. | Menu calculator |
| Arrays · 4 scripts | Indexed and associative arrays, iteration, and statistics. | Marks statistics · Product lookup |
🗺️ Where I want to take this next
These are topics I want to turn into full chapters. Some already appear in the practice scripts; they aren't published lessons yet.
| Area | Planned chapter coverage |
|---|---|
| More Bash lessons | Conditions, loops, functions, script arguments, and arrays. |
| Working with the system | Users, groups, processes, jobs, signals, and more advanced access controls. |
| Everyday Linux | System information, storage, archives, networking, and the shell environment. |
| Better scripts | Handling errors, debugging, checking inputs, ShellCheck, formatting, and making scripts safer to rerun. |
| Useful automation | Backups, file organisation, log processing, and small system utilities. |
| My developer workflow | Command-line tools and scripts that help with everyday software projects. |
The small examples come first. As I get further, I want to build on these exercises with scripts I can use in my own projects, and keep the notes here for revision.
🗂️ How the repository is organised
Published chapters and their examples live under learning/; standalone exercises live under practice/. Planned areas are marked below.
LINUX_LAB/
learning/
linux-commands/ # Command notes, one topic per folder
bash-scripting/ # Bash notes and example scripts
practice/
bash-scripting/ # Exercises: basics, conditions, loops, and arrays
automation/ # Planned: scripts for useful tasks
resources/ # Planned: references and lab material
docs/ # Terminal and editor setup guide
assets/ # README artwork and terminal demos
README.md # You are here
LICENSE
Empty planned folders may not appear in a fresh clone; Git starts tracking them when files are added. The chapter and practice links above take you to the material already available.
You'll need a Linux terminal with Bash and Git.
git clone https://github.com/codewithmahad/LINUX_LAB.git
cd LINUX_LAB
bash learning/bash-scripting/01-shell-and-script-basics/hello.shIt prints Hello From Bash. Already cloned the repo? Open its directory and run the last command.
Files and permissions, text processing, Bash variables, exit statuses, and script checks. Each example below comes from a published chapter.
See 7 skills with examples from the chapters
| What I'm practising | See it in the repo |
|---|---|
| Working with files and paths | Copy, rename, check, and remove a practice submission. |
| Finding and processing text | Find the useful lines in a log, then group and count repeated labels. |
| Saving results and handling errors | Separate output from diagnostics, then see and save a result with tee. |
| Understanding file access | Read and change permission modes, then test directory access. |
| Bash variables, quoting, and input | Compare single and double quotes, and read a value from the person running a script. |
| Arithmetic and command results | Follow numeric comparisons and their exit statuses, then choose the next command based on success or failure. |
| Checking a script before running it | Use Bash's syntax check before executing a file. |
You'll see these three names a lot here:
Linux is the kernel: the core that helps software work with the computer's hardware. People also say “Linux” when they mean a whole operating system built around it.
Ubuntu is one of those complete systems, called a distribution. It gives you Linux together with a desktop, applications, and tools. Bash is a shell: it reads your commands and runs them. Save those commands in a file, and you have the beginnings of a script.
For me, that's the interesting part: learning a command today, then finding a way to use it in my own work.
More about Linux, Ubuntu, and Bash.
The examples use Ubuntu. Choose a setup, then follow the full instructions in the getting-started guide.
| Your setup | Where to start |
|---|---|
| Windows, with Linux commands and Bash | Set up Ubuntu in WSL. |
| A full Ubuntu desktop alongside your usual OS | Set up Ubuntu in a virtual machine. |
| Linux already installed | Open a terminal, check bash --version and git --version, then run the first script. |
Read a small section, guess what its example will do, then run it. Change a value or an option and try again. Keep a scratch directory for file exercises, especially when practising rm: it doesn't send files to the desktop Trash.
Practice: change a script, predict its output, and review lab reminders
Open hello.sh in your editor. Change the greeting, save it, and run the same command again. Then try printing two lines instead of one. That's a small change, but now you're editing a program and checking what it does.
When you move on to variables, replace the fixed greeting with a name stored in a variable. After input and output, try asking the person running it for their name. The same tiny script can grow with you.
Start with the script basics · Give it variables · Make it ask a question
Run this in Bash:
printf 'Division: %s\n' "$((17 / 5))"
printf 'Remainder: %s\n' "$((17 % 5))"
(( 17 > 5 ))
printf 'Exit status: %s\n' "$?"Output:
Division: 3
Remainder: 2
Exit status: 0
Bash's built-in arithmetic uses integers, so division gives 3 and the remainder is 2. The comparison is true, and the command reports success with an exit status of 0.
Change > to < and run the block again. The last number becomes 1. $? reads the status of the command that just ran, so check it immediately after the comparison.
| Try to do this without looking it up | Where to practise |
|---|---|
| Find your current directory, move to its parent, and return to where you were. | Navigation and paths |
| Explain what changes when you use single quotes instead of double quotes around a variable. | Variables and expansion |
Predict which command runs after && or ||, then check your prediction. |
Operators and expressions |
Being able to explain the result is a good reason to move on. If you can't yet, change the example and try again. There's no deadline here.
| Easy to forget | A useful reminder |
|---|---|
| Where a relative path begins | It starts from your current directory. Check with pwd. |
| Spaces in variable assignment | Use name="Shaikh Mahad", with no spaces around =. |
| When variables expand | echo "$name" expands the variable; echo '$name' prints its name literally. |
| Running a Bash script | bash script.sh explicitly chooses Bash and doesn't need executable permission. |
| Checking syntax | bash -n script.sh checks syntax without running the script. |
| Reading an exit status | Check $? immediately after the command you care about. |
These reminders come from the current chapters. Follow the learning map when you want the full examples and explanations.
Use the notes for your lab, revise a topic before an exam, or share a chapter with a friend. If you spot something wrong, open an issue with the chapter, the command you tried, and what happened. Corrections and clearer examples are welcome as pull requests.
I'm working towards becoming a backend developer, with a focus on Java, databases, and Linux. My other repositories show what I'm learning and building alongside this notebook.
GitHub profile · More projects
