Linux and Linux Shell
Operation System, Linux OS, Linux Shell Commands,
Environment Variables and SSH
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
▪ Computers must be protected against unauthorized access,
malicious access to system memory, viruses, worms, etc.
▪ OS security may be approached in many ways
▪ Isolation between processes (RAM, CPU, file system)
▪ Users, groups, permissions (process, file system, others)
▪ Filtering all incoming and outgoing network traffic through a firewall
8
Shell Definition
▪ Shell == command line interpreter
▪ It provides an interface that takes commands and passes them to
the operating system
▪ When in GUI, we use terminal emulators to interact with the shell
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
GUI Shell Services
Linux System
User Processes
System Calls / Functions Memory Management
Process Management Device Drivers Linux Kernel
CPU RAM HDD NET …
Hardware
16
Linux Demo
Simple Commands on the Console
17
Docker Playground
▪ Docker Playground gives you an online Linux virtual machine to
experiment with
▪ Open Docker Playground and log in
▪ Press [Start] and add a new instance
▪ Now you have a Linux environment (Alpine Linux)
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
1 Kernel name 4 Kernel version information
2 Network hostname 5 Machine hardware name
3 Kernel release information
20
Display Linux processes
▪ top [options]
▪ Examples
# Display all active processes in interactive mode
user@host:~$ top
# Display user's processes with 2 sec delay 5 times
user@host:~$ top -d 2 -n 5
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 /
/bin User Binaries /var Variable Files
/sbin System Binaries /tmp Temporary Files
/etc Configuration Files /usr User Programs
/dev Device Files /home Home Directories
/proc Process Information /lib System Libraries
/boot Boot Loader Files
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
user@host:~$ echo 'Hello World!' > hello.txt
user@host:~$ echo 'Hello World!' 1> hello.txt
1 == stdout
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
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 in order (connected)
▪ Pipe: 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
user@host:~$ ls 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
user@host:~$ ls non-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
1 Username (login) 5 Comment (full name, phone, etc.)
2 Password placeholder 6 Home directory
3 User ID 7 User shell
4 Group ID
42
Groups in Linux
▪ Groups file (/etc/group)
root:x:0:
...
wheel:x:10:madmin 4
...
madmin:x:1000:
... 1 2 3
1 Group name 3 Group ID
2 Password placeholder 4 Group members
43
Access Rights
Users, Groups and Permissions in the File System
44
Access Rights in the Linux File System
Group
Owner
Access Rights
read / write / execute
45
File Permissions and Octal Masks
Permissions Octal Mask Description
--------- 000 No permissions
rw-rw-rw- 666 Everyone read + write
rwxr-xr-x 755 Owner full access, others read + execute
rwxrwxrwx 777 Everyone read, write, and execute
46
Access Rights
Read Write Execute
Allow a user to view Allow a user to Allow a user to
the contents of a file modify and delete execute a file (the
Files the file user must also have
read permission)
Allow a user to view Allow a user to Allow a user to
the names of files in delete the directory, access, or traverse
a directory modify its contents into, a directory and
and modify the access metadata
Directories
contents of files that about files in it
the user can read
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
# Switch to a user with a login shell
user@host:~$ su - testuser
# Execute a single command as root
~
user@host: $ sudo chmod +x hello.txt
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]
▪ Change file owner and group
chown [options] [owner][:[group]] file
▪ Change group ownership Can be replaced with "."
chgrp [options] group file
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
▪ Print a single environment variable
printenv HOME
echo $HOME
▪ Sets a new environment variable
export VAR=VALUE
54
Live Demo
Getting to Know Environment Variables
Secure Shell (SSH)
Connecting to Remote Linux Machine
56
SSH (Secure Shell)
▪ Secure Shell (ssh) allows connecting to a remote machine's console
ssh 192.168.0.28 –l root
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
▪ curl == tool for transferring data from or to a server
curl [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
▪ This course (slides, examples, demos, exercises, homework,
documents, videos and other assets) is copyrighted content
▪ Unauthorized copy, reproduction or use is illegal
▪ © SoftUni – https://about.softuni.bg/
▪ © Software University – https://softuni.bg
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