$ run as a normal user# run as root (or with sudo)
What the course covers
What Linux is and why servers use it.
- How to move around the Linux file system.
- Commands to create, copy, move, and delete files.
- Networking, text, and archive commands.
- How to write and run shell scripts.
- A final project and a final exam.
| Module | Main focus |
|---|---|
| Module 1 · about 3 hours | Introduction to Linux: the OS, the kernel, the shell, the file system |
| Module 2 · about 5 hours | Introduction to Linux Commands: info, navigation, files, networking, archives |
| Module 3 · about 4 hours | Introduction to Shell Scripting: variables, logic, loops, functions |
| Module 4 · about 6 hours | Final Project and Final Exam: practice project, final project, exam |
Module 1: Introduction to Linux
Introduction to Linux: the OS, the kernel, the shell, the file system.
- Linux is an open source operating system family built on the Linux kernel. Torvalds started it in 1991, and anyone can read, change, and share the code.
- The kernel is the core of the OS; it manages the CPU, memory, and hardware devices.
- Shell: a program that reads and runs your commands. Bash is the most common shell. The terminal is its window.
- The file system is a tree. It starts at the root
/and shows a full path like/home/student/notes.txt. - Common directories:
/root,/homeuser home folders,/etcconfig files,/binprograms,/varchangeable data,/tmptemporary files. - Absolute path starts with
/; relative path starts from the current folder.~is home,.is here,..is the parent. - Linux is open source. Anyone can read, change, and share its code.
- The kernel sits at the centre. It shares the CPU, memory, and devices.
- Bash is a shell. It takes your typed line and runs it.
- The terminal is the window that connects you to the shell.
- Folders form a tree. The top is
/. /etckeeps settings,/binkeeps programs,/varkeeps data that changes,/tmpkeeps short-lived files.- A path from
/is absolute. A path from where you stand is relative. ~means your home folder..means this folder...means the folder above.
Module 2: Introduction to Linux Commands
Introduction to Linux Commands: info, navigation, files, networking, archives.
- Informational:
whoami(current user),id(user and group IDs),uname -a(kernel info),hostname,df -h(disk free),du -sh(folder size),date,uptime. - Navigational:
pwd(where am I),ls(list),ls -l(long list with permissions),ls -a(show hidden files),cd <dir>(change directory),cd ..(go up). - File management:
mkdir -p <dir>(make folder and parents),touch <file>(create empty file),cp -r <src> <dst>(copy folder),mv(move or rename),rm <file>(delete file),rm -r <dir>(delete folder and contents). - A command has three parts: the name, options like
-l, and arguments like a filename. - Permissions look like
-rwxr-xr-x: readr, writew, executex. The three groups are owner, group, others. chmodchanges permissions (chmod 755 file).chownchanges the file owner.- Text and search:
cat,head,tail,grep <pattern> <file>(matching lines),sed(edit a stream),awk(fields),sort,uniq. - The pipe
|sends the output of one command into the next. Example:ls -l | grep ".txt". - Redirection:
>writes output to a file and replaces it.>>adds to the end.<reads input from a file. - Networking:
hostname -i/ifconfig(IP),ping <host>(reachable?),curl <url>(download or call an API),wget <url>(download),netstat(ports). - Archives:
tar -cvf out.tar dircreates,tar -xvf out.tarextracts,zip -r out.zip dirzips,gzipcompresses. - A command line has a name, then flags like
-l, then the thing to act on. - Ask about the system with
whoami,uname -a,hostname,date, anduptime. - Check space with
df -hfor disks anddu -shfor one folder. - Walk the tree with
pwd,ls,cd <dir>, andcd ... - Make and remove things with
mkdir,touch,cp -r,mv, andrm -r. - Rights are read, write, and execute, in that order: owner, group, then others.
chmodedits rights.chownmoves a file to another owner.- Read text with
cat,head, andtail. Search it withgrep. Cut fields withawk. - A pipe
|hands the left output to the right command. >starts the file again.>>keeps the old text and adds.<feeds a file in.- Test a host with
ping. Fetch a URL withcurlorwget. tar -cvfpacks.tar -xvfunpacks.zip -ralso packs.
Module 3: Introduction to Shell Scripting
Introduction to Shell Scripting: variables, logic, loops, functions.
- A script is a text file full of commands that you run with one call. Start it with a shebang:
#!/bin/bash, which says which shell runs the file. - Make the file executable with
chmod +x script.sh, then run it with./script.sh(orbash script.sh). - Variables:
name="Hosam"thenecho $name; use$to read a value and no spaces around=. Double quotes expand variables, single quotes do not. - Command substitution puts a command's output into a variable:
today=$(date). - Arguments arrive as
$1,$2, ...;$#counts them and$0is the script name. Conditionals useif [ "$x" -eq 5 ]; then ...; fi. Strings compare with=, numbers with-eq,-gt,-lt. - Test a file with
[ -f file ](is a file),[ -d dir ](is a folder),[ -z "$x" ](empty string). - Loops:
for f in *.txt; do echo $f; done, andwhile read line; do ...; done < file. Exit code0means success; read it with$?. set -estops the script when a command fails;exit 1ends it with an error. A function groups commands:name() { echo hi; }.- Scheduling:
crontab -eedits cron jobs; a cron line has five time fields, then the command. - A script is just a file of commands. Line one names the shell:
#!/bin/bash. - Give it the execute bit with
chmod +x, then call./script.sh. - Set a value with
name="Hosam"and read it with$name. Spaces around=break it. - Double quotes fill in variables. Single quotes keep the text as typed.
$(...)runs a command and keeps its output.- Inside a script,
$1is the first input,$#counts inputs,$0is the file name. if [ ... ]; then ...; figuards a block.=compares text.-eq,-gt,-ltcompare numbers.-fasks for a file.-dasks for a folder.-zasks for an empty string.for f in *.txt; do ...; donewalks a list.while read l; do ...; done < fwalks lines.$?holds the last exit code. Zero means good.set -eends the run at the first failure.exit 1reports a failure yourself.- A function gives a name to a group of lines.
crontab -eopens the job table. Five time fields come before the command.
Module 4: Final Project and Final Exam
Final Project and Final Exam: practice project, final project, exam.
- A practice project comes first, then a graded final project with Linux tasks or a script. Plan, test, then submit.
- Start with the practice project, which has no grade. Then the graded project: Linux work or a script. Test it first.
- The exam covers all four modules.
Course topics and key ideas
A shell lets you control the computer with text.
- The course covers Linux and UNIX shell commands.
- Bash is the shell used for scripting in this course.
- You can move through folders and edit files.
- Cron runs jobs on a schedule.
- Scripts let you repeat tasks.
Topics of the course
- What a shell is.
- Linux and UNIX basics.
- Basic commands.
- Finding your way in folders.
- Viewing and editing files.
- Command options and help.
- Pipes and redirection.
- Users and permissions.
- Bash script basics.
- Variables and loops.
- Cron jobs.
- Command line use in cloud and data work.
Why it matters
- Many servers use Linux.
- A shell works well over a remote connection.
- Scripts save time on repeated work.
- Cron can run routine jobs without a person.
Key terms
The words of this course in one table. Learn them before the quiz or exam.
| Term | Meaning |
|---|---|
| Absolute path | Starts at /. Relative path = starts where you are. |
| Archive | Many files in one. tar -xvf opens it. |
| Bash | A common Linux shell used for scripts. |
chmod | Change rights. chown = change owner. |
chmod +x | Allow the file to run. |
| Command | A word or short line that tells the shell what to do. |
| Cron | Timed jobs. Five fields set the time. |
df -h | Disk space in plain units. |
| Directory | A folder. |
| Environment variable | A named value that programs can read. |
| File | A saved set of data or text. |
grep | Find matching lines. |
| Kernel | The part that talks to hardware. |
| Linux | A free, open-source operating system. |
| Open source | Anyone can read and change the code. |
| Path | The address of a file or folder. |
| Permission | A rule about who can read, write, or run a file. |
| Pipe | Left output becomes right input. |
| Rights order | Owner, group, others. |
rm -r | Remove a folder with its contents. |
| Root | /, the top folder. |
rwx | Read, write, execute. |
| Script | A file with commands that run in order. |
set -e | Stop on the first error. |
| Shebang | The #! line that picks the shell. |
| Shell | The program that runs your typed lines. |
| Terminal | The window for the shell. |
| UNIX | An older family of operating systems. Linux is like it. |
Check yourself
Answer each question first, then open it to check the answer.
1What does the Linux kernel do? a) It hosts websites · b) It manages the CPU, memory, and hardware · c) It edits text files · d) It stores Git history
b) It manages the CPU, memory, and hardware. The kernel is the core of the OS and controls hardware and memory.
4You want to delete a folder and everything inside it. Which command is correct? a) rm folder · b) rm -r folder · c) mkdir folder · d) cp folder
b) rm -r folder. -r means recursive, so the folder and its contents go.
5In -rwxr-xr-x, what does the first group rwx describe? a) Permissions of the owner · b) Permissions of all other users · c) The file size · d) The file owner's name
a) Permissions of the owner. The first rwx is for the owner; the next r-x is for group and others.
6What does the pipe | do? a) Saves output to a file · b) Sends the output of one command into the next · c) Deletes a file · d) Runs a command in the background
b) Sends the output of one command into the next. A pipe connects the output of one command to the input of the next.
8What does >> do? a) Reads input from a file · b) Adds output to the end of a file · c) Replaces the file with new output · d) Sends a file over the network
b) Adds output to the end of a file. > overwrites a file; >> appends to it.
9What is the first line of a Bash script usually called? a) The shebang, for example #!/bin/bash · b) The variable line · c) The comment block · d) The exit code
a) The shebang, for example #!/bin/bash. The shebang tells the system which interpreter runs the script.
10How do you make a script file runnable with ./script.sh? a) chmod +x script.sh · b) chmod -r script.sh · c) rm script.sh · d) cat script.sh
a) chmod +x script.sh. chmod +x adds the execute bit.
11Which command creates a zip archive of a folder? a) tar -xvf out.tar · b) zip -r out.zip folder · c) unzip out.zip · d) gzip -d out.zip
b) zip -r out.zip folder. -r means recursive, so the whole folder is included.
12Which part of Linux shares the CPU and memory between programs? a) The shell · b) The kernel · c) The terminal · d) The home folder
b) The kernel. The kernel sits between the programs and the hardware.
13You type whoami. What comes back? a) Your user name · b) The folder path · c) The kernel version · d) The free space
a) Your user name. whoami prints the account name and nothing else.
14Which path is relative? a) /etc/hosts · b) ../notes.txt · c) /home · d) /
b) ../notes.txt. It starts from the current folder, not from /.
15You are in /home/student/docs and run cd ... Where are you? a) /home/student · b) /home · c) /home/student/docs · d) /
a) /home/student. .. is the folder one level up.
16Which listing includes files that start with a dot? a) ls · b) ls -a · c) ls -l · d) ls -t
b) ls -a. -a adds hidden entries, which begin with a dot.
17Which command makes nested folders in one call? a) mkdir -p /data/logs · b) mkdir /data/logs · c) touch /data/logs · d) cp /data/logs
a) mkdir -p /data/logs. -p builds every missing parent folder.
18In -rw-r--r--, what may the owner do? a) Read only · b) Read and write · c) Execute only · d) Nothing
b) Read and write. The owner holds rw, so read and write.
19Which command lets the owner run deploy.sh? a) chmod u+x deploy.sh · b) chmod u-x deploy.sh · c) chown u+x deploy.sh · d) rm deploy.sh
a) chmod u+x deploy.sh. u+x adds execute for the user who owns the file.
21What does cat a.txt | sort do? a) Saves a sorted copy · b) Sorts the text and prints it · c) Deletes a.txt · d) Edits a.txt
b) Sorts the text and prints it. The pipe feeds the file text into sort.
22Which symbol replaces the old text in a file? a) >> · b) > · c) < · d) |
b) >. > clears the file first. >> appends.
23Why does a script start with #!/bin/bash? a) It chooses the shell that runs it · b) It prints a title · c) It sets the first variable · d) It adds a comment only
a) It chooses the shell that runs it. The #! line tells the system which shell to use.
24In a script, $# tells you what? a) The script name · b) How many inputs came in · c) The first input · d) The last exit code
b) How many inputs came in. $# is the count of arguments.
25Which test passes only when logs is a folder? a) [ -f logs ] · b) [ -d logs ] · c) [ -z logs ] · d) [ -x logs ]
b) [ -d logs ]. -d is true for a directory.
26Which line reads a file one line at a time? a) if read l; then · b) while read l; do ...; done < f · c) for f in *.txt · d) case l in
b) while read l; do ...; done < f. The while read loop takes one line per round.
27A command returns exit code 2. What does it mean? a) Success · b) Failure · c) Still running · d) No output
b) Failure. Any code other than 0 means a problem.
28What does set -e change? a) The script stops at the first failed command · b) The script runs twice · c) Every line is printed · d) Variables are cleared
a) The script stops at the first failed command. One failed command stops the whole run.
29In a crontab line, which field is first? a) Minute · b) Hour · c) Command · d) Day
a) Minute. A crontab line starts with minutes.
31Which pair packs a folder and then shrinks the file? a) tar -cvf then gzip · b) tar -xvf then rm · c) unzip then cp · d) mv then chmod
32What does a shell let you do?
It lets you control the computer with text.
33What does Bash help you write?
It helps you write scripts.
34What does cron do?
It runs jobs on a schedule.
Study and exam tips
Practise the real commands in the lab; typing them beats reading.
- Learn
>vs>>, and-rvs no-r. - For permissions, remember the order: owner, group, others.
- In scripts, watch the shebang,
chmod +x, and$?. - Read any command as three parts: name, options, arguments.
- Type the commands in the lab. Your hands learn faster than your eyes.
- Keep the pairs apart:
>vs>>,..vs.,-fvs-d. - For rights questions, read the string in three blocks: owner, group, others.
- In a script, check the shebang, the execute bit, and
$?first. - If two commands look valid, pick the one that changes only what the question asks.
Useful links
Official documentation and pages for this course.