StudyCorner
Back

Computing and the Command Line · Course 1 of 4

The Shell and the Command Line

Bash from the first prompt to working scripts, practised on Ubuntu under WSL and carried straight over to a Linux desktop. Files and the directory tree, permissions and sudo, redirection and pipelines, expansion and quoting, the environment, processes and jobs, editing in the terminal, and shell scripts, each with commands to type and exercises with answers.

24 lessons ~3 h 8 units

0 of 24 done
Start learning
Unit 1

First Steps

3 lessons · 20 min

  1. 1 The Terminal, the Shell, and the Prompt In a Linux desktop’s terminal, you select some text and press Ctrl-C to copy it while a program is running. What happens? The shell is a program that reads commands and runs other programs; the terminal is the window it lives in. Bash is the standard shell on Linux. Read the prompt (user, host, working directory, $ or… 7 min Next up
  2. 2 A Linux Shell on Windows: WSL Windows can run Linux programs through WSL 2. How does it manage that? The quickest way to practice real Linux before switching: the Windows Subsystem for Linux. WSL 2 runs a genuine Linux kernel in a lightweight virtual machine. Install Ubuntu with one command, create… 6 min Next up
  3. 3 Getting Help and Typing Less passwd is the name of both a command and a system file. How does the built-in manual keep their two pages apart? Four kinds of commands (programs, builtins, functions, aliases) and how type and which tell them apart. Where help lives: help for builtins, --help, man pages and their sections, apropos and whatis… 7 min Next up
Unit 2

Files and the Filesystem

3 lessons · 22 min

  1. 4 Paths and the Directory Tree cat /proc/cpuinfo prints a description of your processor. Where on the disk is that file kept? Linux has one directory tree rooted at /, with no drive letters; other disks are mounted into it. A tour of the standard directories (/etc, /home, /usr, /var, /tmp, /dev, /proc). Absolute and… 7 min Next up
  2. 5 Looking at Files: ls -l, less, and Friends How does Linux store nearly all of its system settings? Read every column of ls -l (type, permissions, links, owner, group, size, date, name) and use the options that matter: -a, -h, -t, -r, -S, -d, -F. Find out what a file really is with file, then look… 7 min Next up
  3. 6 Creating, Copying, Moving, Linking, and Deleting You use mv to move a 40 GB folder into another folder on the same disk. About how long does it take? mkdir and touch to create; cp with -r, -i, -a, and -u to copy; mv to move and rename; rm and rmdir to delete, with no trash and no undo. Wildcards (*, ?, [abc], [[:digit:]]) to work on many files at… 8 min Next up
Unit 3

Permissions, Users, and sudo

3 lessons · 22 min

  1. 7 Reading Permissions A file lets its group read it but gives its owner no access at all. The owner is in that group. Can the owner read it? Every file has an owner, a group, and nine permission bits: read, write, and execute for the owner, the group, and everyone else. Find out who you are with id, see where users and groups are defined… 6 min Next up
  2. 8 Changing Permissions and Ownership Your password is kept in a file only root may write, yet you can change it without sudo. How? chmod in octal (644, 755, 600, 700, and why r=4, w=2, x=1) and in symbolic form (u, g, o, a with +, -, =). Make a script runnable with chmod +x. umask sets what new files start with. chown and chgrp… 9 min Next up
  3. 9 Root and sudo On a fresh Ubuntu install, what is the root account’s password? Root can do anything, which is why you don't work as root. Ubuntu locks the root account and grants power one command at a time through sudo, with your own password and a short grace period; since… 7 min Next up
Unit 4

Redirection and Pipelines

3 lessons · 21 min

  1. 10 Standard Input, Output, and Error To sort a file in place, you run sort notes.txt > notes.txt. What’s in notes.txt afterward? Every program has three streams: standard input (0), standard output (1), and standard error (2). Send output to files with > and >>, errors with 2>, both with 2>&1 or &>, and unwanted output to… 7 min Next up
  2. 11 Pipelines and Filters A script saved by a Windows editor fails under Linux with odd ‘command not found’ errors on every line. The likely cause? The pipe, |, connects one program's output to the next one's input. The filters that make pipelines useful: sort (-n, -r, -h, -k, -t, -u), uniq (-c, -d, and why it needs sorted input), cut, tr, wc… 7 min Next up
  3. 12 Finding and Searching: find and grep In a folder holding one PDF, report.pdf, you run find ~ -name *.pdf with no quotes. What does find search for? grep prints lines that match a pattern: -i, -v, -n, -c, -l, -r, -w, and -E. Regular expressions: anchors, the dot, brackets and character classes, repetition, and alternation. find walks a directory… 7 min Next up
Unit 5

How the Shell Reads a Command

3 lessons · 21 min

  1. 13 Expansion and Quoting Putting echo in front of rm *.log shows exactly which files rm would delete. Why does that work? Before any program runs, bash rewrites your line: brace expansion, tilde, parameters, arithmetic, command substitution, word splitting, filename expansion, and quote removal, in that order. What… 8 min Next up
  2. 14 Variables, PATH, and Aliases Meaning to add a tools folder, you run PATH=~/tools. What happens the next time you type ls? Shell variables versus environment variables, and how export passes a value to the programs you start. The common environment variables (HOME, USER, PATH, EDITOR, LANG). How the shell finds a… 7 min Next up
  3. 15 Startup Files and the Prompt Ubuntu’s default bash settings keep one of these out of your command history. Which? Login and non-login shells, and which startup files each reads: /etc/profile, ~/.profile, /etc/bash.bashrc, and ~/.bashrc. Where to put PATH and EDITOR versus aliases, functions, and the prompt… 6 min Next up
Unit 6

Processes and Jobs

3 lessons · 20 min

  1. 16 What a Process Is top says your 16 GB machine has only 1 GB free, with 9 GB under ‘buff/cache’. Is it short of memory? A process is a running program. The kernel starts systemd as process 1, which starts the background services (daemons), and every program you run is a child of your shell. See them with ps (ps, ps… 7 min Next up
  2. 17 Jobs and Signals A job running in the background stops to ask you a yes-or-no question. What happens? Run a command in the background with &, pause the foreground job with Ctrl-Z, and move jobs between foreground and background with fg and bg. Signals are how processes are told to stop: INT from… 7 min Next up
  3. 18 Exit Status and Chaining You run test -d backup && cp big.iso backup/ || echo 'no backup folder'. The folder exists, but the disk fills mid-copy. What do you see? Every command ends with an exit status in $?: 0 for success, 1 to 255 for some kind of failure. Use it to chain commands: ; always continues, && only after success, || only after failure, and why a… 6 min Next up
Unit 7

Editing in the Terminal

2 lessons · 10 min

  1. 19 nano: Quick Edits You open nano on a file name that doesn’t exist yet, type a line, then quit without saving. What’s on the disk? nano is the friendly terminal editor installed on Ubuntu: open a file, type, Ctrl-O to save, Ctrl-X to quit. Read the help bar (^ is Ctrl, M- is Alt), search and replace, cut and paste lines, undo… 4 min Next up
  2. 20 vim Essentials You open a file in vim and start typing a sentence straight away. What happens? Why learn vi: it's on every Unix system, required by POSIX, and you'll land in it sooner or later. vim's modes (Normal, Insert, Visual, Command-line), how to get out (Esc, :q!), and how to save… 6 min Next up
Unit 8

Shell Scripting

4 lessons · 34 min

  1. 21 Your First Script A script runs rm -rf "$BACKUPDIR/"*, but the variable it set is really BACKUP_DIR. What does bash do with that line? A script is a file of commands. The shebang line, making it executable, and where to keep it so it runs by name. Variables, constants, quoting, printf, reading input, sending errors to standard… 8 min Next up
  2. 22 Decisions and Loops A loop runs for f in $(ls) in a folder holding one photo, Summer 2026.jpg. How many times does it run? if, elif, and else branch on a command's exit status. Tests with [[ ]] for files, strings, regular expressions, and numbers, and (( )) for arithmetic. case for matching patterns. for loops over… 8 min Next up
  3. 23 Arguments and Functions A bash function works out a folder’s size. How does it hand that value back to the code that called it? Positional parameters: $0, $1 to $9, ${10}, $#, "$@" versus "$*", and shift. Defaults and required arguments with ${1:-...} and ${1:?...}, usage messages, and options with getopts. Functions with… 8 min Next up
  4. 24 Project: a Snapshot Backup Script A backup script works when you type its name, but the nightly scheduled run fails with ‘command not found’. Most likely why? Put the whole course together in a real tool: a script that copies your important folders to a backup drive as dated snapshots, using rsync's --link-dest so unchanged files are hard links and every… 10 min Next up