01 Linux and Linux Shell
01 Linux and Linux Shell
SoftUni Team
Technical Trainers
Software University
https://about.softuni.bg
1
Have a Question?
sli.do
#Dev-Ops
2
Table of Contents
1. Operating System
2. Linux Operating System
3. Linux File System
4. Input/Output Streams
5. Command Sequences
6. Users and Groups
7. Access Rights
8. Environment Variables
9. Secure Shell
10. Processes
11. More Linux Commands
Operating System
Definition, Functions, Components, Examples
4
What is an Operating System?
▪ The operating system (OS) controls the computer (device)
▪ Controls the hardware, processes (programs), resources, users
▪ Manages computer hardware, software resources, and provides
common services for computer programs
▪ It also coordinates all of this to make sure each program gets what
it needs
▪ Allows users to communicate with the computer without knowing
how to speak the computer's language
5
Important Functions of Operating Systems
▪ Process management (programs, which run in the OS)
▪ Process scheduling – OS decides which process gets the processor,
when and for how much time
▪ Keeps tracks of processor and status of a process
▪ Memory management
▪ Keeps tracks of primary memory (RAM), allocates / de-allocates
memory for each process
▪ Users / privileges management
▪ Device management, file management, security, etc.
6
Operating Systems Components
▪ Kernel
▪ Essential OS component that loads first and remains within the main memory
▪ Provides the basic level of control of all the computer peripherals
▪ Shell
▪ An interface between the OS and the user
▪ Helps users access the services, provided by the OS
▪ It might be a command-line interpreter (CLI) or GUI app
▪ Utilities == small programs that provide additional
capabilities to those, provided by the operating system
▪ е.g., text editor, ZIP archiver, remote shell (SSH)
7
OS Security
▪ OS security refers to providing a protection system for
computer system resources and most importantly data
9
Linux Operating System
Architecture, Advantages and Disadvantages, Distribution
10
What is Linux?
▪ Linux OS is a very popular free, open-source
operating system
▪ https://github.com/torvalds/linux
▪ Many distributions (variants), e.g., Ubuntu, Alpine,
CentOS
▪ Linux is NOT the complete OS, it is just the Linux Kernel
▪ Often the term is used to refer to the whole OS (Linux OS)
▪ Linux Kernel is distributed along with all the necessary
software and utilities, so that it can be used as an OS 11
Linux Distributions
▪ Linux has many distributions (vendors)
▪ Differences in console commands, file locations, package
management systems
▪ Most popular Linux distributions
▪ Ubuntu – user-friendly, stable, popular
▪ Alpine – minimal, secure, lightweight
▪ CentOS – enterprise-grade, stable, secure
▪ Debian – robust, reliable, versatile
▪ Fedora – community version of Red Hat Enterprise Linux
12
Linux Advantages
▪ Linux is the most popular OS in the world
▪ You have many, many resources, available everywhere
▪ Books, tutorials, videos, forums, questions / answers, certification
programs, software, tools, etc.
▪ Linux is open-source, so anyone can contribute / enhance it
▪ Linux is more secure in comparison to other operating systems
▪ In Linux there is a larger number of software updates
▪ Linux provides high performance and efficiency
13
Linux Disadvantages
▪ Availability of apps: some applications that work on other OS do
not work in Linux
▪ Other OS (like macOS, Windows) have better usability (UI and UX)
▪ Learning curve
▪ It takes time and effort to master Linux
▪ Lack of standardization
▪ Many distributions == many differences
▪ Some hardware drivers are not available for Linux
14
Linux OS Components
▪ System components
▪ Boot loader Applications
Support
▪ Boot manager
Daemons
▪ Kernel
Shell
GUI
▪ User components
Docs &
Guides
▪ Daemons (services)
▪ Shell (command line) Kernel
▪ Graphical environments
Boot Manager
▪ User applications
Boot Loader
▪ Documentation and Support
15
Linux System Architecture
User Processes
18
Display the Current User
▪ The whoami command displays the currently logged-in user
▪ Example
user@host:~$ whoami
19
Check Linux System Info
▪ Type the uname -a command to print OS information
20
Display Linux processes
▪ top [options]
▪ Examples
21
File System in Linux
Files, Directories and Basic Commands
22
The File System in Linux
▪ File system == OS component, which organizes and manages
files and directories on a storage device (e.g., SSD disk)
▪ Popular file systems: ext4, BTRFS, ZFS, NTFS
▪ Most Linux distributions use ext4 file system
▪ Storage is organized in directories, which hold files and
other directories
▪ Files hold data (e.g., text data / binaries)
▪ Special files: symlinks, pipes, sockets, …
23
List files and directories
▪ Syntax
ls [options]
▪ Examples
user@host:~$ ls
user@host:~$ ls -al
24
File Types
▪ Files and directories
▪ Regular (-)
▪ Directory (d)
▪ Special files
▪ Symbolic link (l)
▪ Block (b)
▪ Character (c)
▪ FIFO pipe (p)
▪ Local socket (s)
25
Examine Root Directory files
▪ Syntax
ls /
26
Absolute vs Relative Path
▪ Absolute path (starts with /)
▪ Calculated from the root of the file system tree, e.g., /dev/random
▪ Relative path (no leading /, uses . and ..)
▪ Calculated from the current working directory, e.g., ../../bin/
▪ If we are in /home/user and we want to list folders
# Absolute notation
user@host:~$ ls –al /usr/bin
# Relative notation
user@host:~$ ls -al ../
27
Files and Directories
▪ Create directories
mkdir [options] directory [directory …]
▪ Copy files and directories
cp [options] source dest
▪ Move/Rename files
mv [options] source dest
▪ Remove files or directories
rm [options] file [file …]
28
Files and Directories
▪ Print the current working directory
pwd
▪ Output the first part (10 lines by default) of files
head [options] [files]
▪ Output the first part (10 lines by default) of files
tail [options] [files]
▪ Read data from the file and return the content as output
cat [filename]
29
Input / Output Streams
Standard File Descriptors. Redirection
30
Standard File Descriptors
▪ stdin == standard input stream (N.0)
▪ stdout == standard output stream (N.1)
▪ stderr == standard error output stream (N.2)
#2 stderr
Display
#1 stdout
Application /
Keyboard #0 stdin Process
Terminal
31
Redirect Output (>)
▪ Redirect output streams (stdout or stderr) with
target overwrite
▪ Examples The same
32
Redirect Output with Append (>>)
▪ Redirect output streams (stdout or stderr) with
target append
▪ Example
user@host:~$ echo 'Line #2' >> file.txt
33
Redirect Input (<)
▪ Redirect input stream (stdin)
▪ Usually, it is omitted
▪ Examples
user@host:~$ cat < hello.txt
The same
34
Command Sequences
Execute Multiple Commands. Substitution
35
Commands Sequences
▪ Execute in order (disconnected)
▪ Sequence: command1 ; command2
▪ Execute conditionally
▪ On Success: command1 && command2
▪ On Failure: command1 || command2
36
Sequence (;)
▪ Always execute next command
▪ Example
user@host:~$ ls non-existing-file.txt ; echo Ok
37
Pipe (|)
▪ Chaining two or more programs' output together
▪ Example
user@host:~$ ls | sort | head -n 3
38
On Success (&&)
▪ Next command is executed if previous one exited with a status
of 0 (success)
▪ Examples
user@host:~$ ls non-existing-file.txt && echo Ok
39
On Failure (||)
▪ Next command is NOT attempted if previous one exited with 0
▪ Examples
user@host:~$ ls existing-file.txt || echo Ok
40
Users and Groups
Manage Users and Groups
41
Users in Linux
▪ Users file (/etc/passwd)
root:x:0:0:root:/root:/bin/bash
...
madmin:x:1000:1000:M.Admin:/home/madmin:/bin/bash
... 1 2 3 4 5 6 7
Group
Owner
Access Rights
read / write / execute
45
File Permissions and Octal Masks
47
SUDO (SuperUser DO) Configuration
▪ sudo is used to access restricted files and operations
▪ Controls who can do what and from where
▪ Temporarily allows ordinary users to
perform administrative tasks
▪ Without logging in as the root user
sudo [command]
48
sudo
▪ Execute a command as another user
# Execute commands as another user
user@host:~$ sudo -u testuser whoami
# Switch to a user
user@host:~$ sudo su testuser
49
Commands
▪ Change the permissions of a file or directory for all types of users
▪ Operations modify the user or file level permissions
chmode [operations] [file/directory name]
50
Live Demo
Getting to Know the Console
Environment Variables
52
Linux Environment Variables
▪ Environment variables == dynamic variables used by the Linux shell
▪ Provide config settings to Linux apps
▪ They follow the <NAME>=<VALUE> formatting
▪ They are case-sensitive
▪ By convention environment
variable names use CAPITAL_LETTERS
53
Commands
▪ List all environment variables
env
printenv
57
Processes
Monitoring and Management
Processes and Jobs
▪ Process
▪ Running a program with
its own address space
▪ Job
▪ Interactive program
that doesn't detach
▪ It can be suspended with [Ctrl]+[Z]
▪ It can execute in the foreground or background mode
59
Commands
▪ Display status of jobs
jobs [options] [jobspec]
▪ Report a snapshot of the current processes
ps [options]
▪ Send a signal to a job or process
kill [options] pid | jobspec
▪ Kill processes by name
killall [options] process
60
More Linux Commands
apt
▪ apt provides a high-level command line interface for the package
management system
apt install <package>
▪ Download package information from all configured sources
apt update
▪ Install available upgrades of all packages, currently installed on the
system, from the configured sources
apt upgrade
62
Data Fetching
▪ wget == free utility for non-interactive download of files from
the Web
wget [options] URL
63
Live Demo
Getting Help
Summary
▪ ▪Operating
… systems manage all of the software
and hardware on the computer
▪ …
▪ Linux OS distributions & file system
▪ …
▪ Shell definition
▪ Command sequences
▪ Environmental variables – dynamic named
variables
▪ Linux commands – used to interact with
the system 65
Questions?
SoftUni Diamond Partners
License
68
Trainings @ Software University (SoftUni)
▪ Software University – High-Quality Education,
Profession and Job for Software Developers
▪ softuni.bg, about.softuni.bg
▪ Software University Foundation
▪ softuni.foundation
▪ Software University @ Facebook
▪ facebook.com/SoftwareUniversity
▪ Software University Forums
▪ forum.softuni.bg 69