Professional Documents
Culture Documents
Slides 2
Slides 2
andreas.woelfl@th-deg.de
THE LINUX OPERATING SYSTEM
THE LINUX OPERATING SYSTEM
1. MOTIVATION
MOTIVATION
1
Source: It’s FOSS
2
Source: Hayden James
3
Source: ZDNET
4
Source: Kernel Development Report
5
Source: Medium
Prof. Dr. Andreas Wölfl Operating Systems and Networks 1
MOTIVATION
Linux Kernel
A Linux distribution is a specific
combination of these components.
Computer Hardware
The Linux kernel was created6 and is still maintained by Linus Torvalds:
6
In the year 1991
Prof. Dr. Andreas Wölfl Operating Systems and Networks 3
MOTIVATION
He is famous for rants and general hostility directed at other Linux developers.
7
A program which is responsible for the input and output coordination of users.
Prof. Dr. Andreas Wölfl Operating Systems and Networks 6
MOTIVATION
8
Long-Term Support
Prof. Dr. Andreas Wölfl Operating Systems and Networks 7
THE LINUX OPERATING SYSTEM
2. THE SHELL
THE SHELL
The Shell
The shell is a program that provides a command-line interface that allows text
input to interact with a Linux system.
• Users can enter shell commands via the Linux console9 mode.
• Most Linux distributions start several virtual consoles that are accessible
from a single keyboard and monitor (CTRL + ALT + F1-F7).
• In addition, most Linux distributions provide a terminal emulator program
that can be started from the desktop environment to interact with a shell.
9
Originating from the old days where hardwired console terminal were used to access UNIX.
Prof. Dr. Andreas Wölfl Operating Systems and Networks 8
THE SHELL
awoelfl@abtschlag:~$
10
Bourne-Again shell, written by Brian Fox for the GNU project. Default shell in Ubuntu.
Prof. Dr. Andreas Wölfl Operating Systems and Networks 10
THE SHELL
Commands
Commands are programs that are executed when a user enters the program
name at the shell prompt and presses Enter at the keyboard.
11
Brackets indicate an optional part of the syntax.
Prof. Dr. Andreas Wölfl Operating Systems and Networks 11
THE SHELL
→ Becoming familiar with the manual is invaluable for working with Linux.
One method for getting things done faster is using the command-line history.
Typically, the last 1000 executed commands are kept in the history list.
The history command without options or arguments shows the history list:
1 $ history
Useful key combinations to interact with the history on the shell prompt:
Task
Solve the task ”Shell Commands” in iLearn.
Environment Variables
The shell supports declaring environment variables, which are used to provide
the ability to configure a value outside a program.
12
Variable names should have all capital letters with underscores as seperators.
Prof. Dr. Andreas Wölfl Operating Systems and Networks 16
THE SHELL
ENV Description
USER The name of the current user account.
HOME The absolute path to the user’s home directory.
PWD The absolute path to the current working directory.
PATH Colon-separated list where the shell searches for commands.
HOSTNAME The name of the computer.
3. FILES
FILES
Everything is a file
Virtual directory
Linux stores files within a single directory structure, called a virtual directory,
that contains file paths from all storage devices installed in the computer.
Example: /home/awoelfl/documents/exam.pdf
13
Similar to the way Windows does it.
Prof. Dr. Andreas Wölfl Operating Systems and Networks 19
FILES
The Linux directory structure is standardized with the Linux Filesystem Hierarchy
Standard (FHS):
/ The root of the virtual directory. No files should be placed here.
/bin The binary direrctory, where user-level utilities are stored.
/boot The boot directory, where boot files are stored.
/dev The device directory, where Linux creates device nodes.
/etc The system configuration files directory.
/home The Home directory, where Linux creates user directories.
/lib The libraries directory, where program library files are stored.
The Linux directory structure is standardized with the Linux Filesystem Hierarchy
Standard (FHS):
/opt The optional directory, often used to store optional software packages.
/root The root user account’s Home directory.
/sbin The system binary directory, where admin-level utilities are stored.
/tmp The temporary directory, used for temporary work files.
/usr The user-installed software directory.
/var The variable directory, for files that change frequently (e.g. logs)
• touch. Examples:
1 $ touch myfile3.txt # creates an empty file named myfile3.txt
Globbing
A shell feature that is used for matching or expanding specific types of patterns.
Common patterns:
• ? matches a single character: • [] matches a range of characters:
1 $ ls -la ????.txt 1 $ ls -lah [a-zA-Z].txt
Alias
Short command that translates into another (usually longer) command.
Note: Many distributions ship with a predefined set of aliases (e.g. ll).
Task
Solve the task ”Files and Directories” in iLearn.
Filesystem
Method and data structure used by the operating system to control how data
and in which format data is stored to and retrieved from a hard drive.
14
This process is called formatting
Prof. Dr. Andreas Wölfl Operating Systems and Networks 30
FILES
The mount command mounts the filesystem on a device to the virtual directory:.
1 $ mount /dev/sdb /mnt/data
The Linux Filesystem Hierarchy Standard (FHS) proposes for mount points:
/mnt The mount directory, place for mount points for removable media.
/media The media directory, place for mount points for removable media.
Note: Only the root user is able to execute the mkfs/mount/umount commands.
Task
Solve the task ”Mounting Disks” in iLearn.
File Descriptor
A file descriptor is a non-negative interger that uniquely identifies open files.
The operating system reserves the first three file descriptors for each process:
File Descriptor Abbreviation Description
0 STDIN Standard Input
1 STDOUT Standard Output
2 STDERR Standard Error
→ These three special file descriptors are called the standard streams and
handle the input and output of processes.
1: stdout
TTY 2: stderr
/dev/tty0
Process
0: stdin
15
/dev/tty* represent physical terminals or virtual consoles, whereas /dev/pts/* represent
terminal emulator programs (pseudoterminals).
Prof. Dr. Andreas Wölfl Operating Systems and Networks 34
FILES
1: stdout
TTY 0: stdin
/dev/tty0
Process /dev/null
2: stderr
Pipe
A pipe is a unidirectional data channel that can be used for interprocess
communication.
TTY 0: stdin
Process A Process B
/dev/tty0 2: stderr
2: stderr
Task
Solve the task ”Standard Streams” in iLearn.
Each individual who accesses a Linux system requires a unique user account:
• The user account root has the UID 0 and has special privileges and overrides
most protection rules.
Privilege Delegation
The sudo (su16 do) command allows a system administrator to give certain users
(or groups) the ability to run some (or all) commands as root user.
Example:
1 $ sudo mount /dev/sdb /mnt/disk2
Understanding permissions:
• r (read): Permission to read the file. rwxr-xr--
• w (write): Permission to write to the file.
owner group world
• x (execute): Permission to execute the file.
Setting permissions for owner(u), group(g), and world(o) with chmod. Example:
1 $ chmod u=rwx,g=rw,o=r file.txt # setting permissions exactly
2 $ chmod g+w file.txt # incrementally add permissions
3 $ chmod g-w file.txt # incrementally remove permissions
4 $ chmod +x file.txt # set permissions for all categories
17
In many Debian based Linux distributions, the sudo group is preinstalled and its members are
granted the permission to execute the sudo command.
Prof. Dr. Andreas Wölfl Operating Systems and Networks 46
TASK
Task
Solve the task ”Users & Groups” in iLearn.
5. PACKAGE MANAGEMENT
PACKAGE MANAGEMENT
Note: A software package will often have dependencies, or other packages that
must be installed first.
Software packages are stored on servers, called repositories, and are accessed
via package management system utilities running locally on the Linux system:
Metadata
Package
User Repository
Manager
Packages Dependencies
Note: Metadata in general is data that describes other data. In context of the
diagram, the metadata gives information about the packages in the repository.
Prof. Dr. Andreas Wölfl Operating Systems and Networks 49
PACKAGE MANAGEMENT
High Level
apt zypper dnf pacman
Package Manager
Low Level
dpkg rpm
Package Manager
Linux system
Focus in this lecture
18
That includes Ubuntu, Mint, Deepin, Kali, Raspbian,...
19
Note that other distributions may have different package management systems.
Prof. Dr. Andreas Wölfl Operating Systems and Networks 51
PACKAGE MANAGEMENT
20
i.e., independent of the Linux distribution
21
The company behind the Ubuntu distribution.
Prof. Dr. Andreas Wölfl Operating Systems and Networks 55
TASK
Task
Solve the task ”Software Packages” in iLearn.
6. TERMINAL EDITORS
TERMINAL EDITORS
22
https://www.youtube.com/c/ThePrimeagen
23
https://www.youtube.com/playlist?list=PLm323Lc7iSW_wuxqmKx_xxNtJC_hJbQ7R
Prof. Dr. Andreas Wölfl Operating Systems and Networks 57
TERMINAL EDITORS
Task
Solve the task ”Terminal Editors” in iLearn.
7. SCRIPTING
SCRIPTING
Shell Script
A shell script is a text file that contains a sequence of commands that is carried
out by the shell.
• Where shell commands are a powerful way to accomplish a task, there are
times when it is not efficient.
• If a certain task requires multiple commands to execute, a single shell script
can handle the job faster.
• Rule of thumb: A task that is carried out more than 3 times should be
scripted.
1 #!/bin/bash
2 # This sample script displays the date/time
3 # and who is logged onto the system
4 date
5 who
• The first line is called the shebang (#!) and tells the current shell which shell
to use for running the script.
• Lines 2-3 are comments (start with #) and are not interpreted by the shell.
• Lines 4-5 contain the commands that are executed in sequence.
It is executed as follows
1 $ ./sampleScript1.sh
2 $ sh ./sampleScript1.sh
Best practise: Use the .sh file extension for shell scripts.
1 #!/bin/bash
2 # Display a user's information
3 echo "User info for userid: $USER"
4 echo "UID: $UID"
5 echo "HOME: $HOME"
1 #!/bin/bash
2 # Trying out user variables
3 days=10
4 guest="London Ratford"
5 echo "$guest checked in $days ago."
6
7 days=5
8 guest="Takoda Puddle"
9 echo "$guest checked in $days ago."
1 #!/bin/bash
2 # Trying out command substitution variables
3 testDate="$(date)"
4 echo "The date and time are: $testDate"
• The variable testDate receives the output from the date command.
• Line 4 prints the value of the testDate variable.
1 #!/bin/bash
2 # Trying out command-line parameters
3 echo "Hello $1, glad to meet you.
1 #!/bin/bash
2
3 function greet() {
4 echo "Hello $1"
5 }
6
7 greet "Kai"
8 greet "Ben"
Functions (sampleScript6.sh):
Further reading:
→ Once you are familiar with control structures, read about advanced shell
scripting in [3], Chapter 19.
8. SUMMARY
SUMMARY
Summary
You should have accquired the competencies to (1)
Summary
You should have accquired the competencies to (2)