Os
Os
Introduction to
Operating System (OS)
Mrinalini Kakroo
What is an Operating System (1)?
• A modern computer consists of:
One or more processors
Main memory
Disks
Printers
Various input/output devices.
• Managing all these varied components
requires a layer of software – the
Operating System (OS).
2 Mrinalini Kakroo
?What is an Operating System (2)
• An Operating System is a program that acts as
an interface between a user of a computer and
the computer hardware.
• OS goals:
– Make the computer system convenient to use.
– Ease the solving of user problems.
– Efficiently use the computer hardware.
3 Mrinalini Kakroo
?Where does the OS fit in
4 Mrinalini Kakroo
Operating Systems Need
• Without OS every simple
task (e.g. reading a file) user
needs to write a code and
communicate to hardware
about what needs to be done
but every time coding for
every user is not possible
and also time consuming.
• So to solve this problem, OS
comes to rescue by acting as
an interface and provides
user friendly environment
5 Mrinalini Kakroo
Key Functions of OS
• Interface between user and hardware.
• Process management
• Memory management
• File system management
• Resource allocation
6 Mrinalini Kakroo
UNIX OVERVIEW
• Unix OS is a set of program that acts as a link between computer and user.
• Unix is still widely used by its creators (familiarity)
• KEY FEATURES
1. Multi-tasking
2. Multi-user
3. Portable
4. CLI (user interaction with system)
5. Scalability(used on small system to large system)
7 Mrinalini Kakroo
UNIX ARCHITECTURE
8 Mrinalini Kakroo
ADVANTAGES &DIS-ADVANTAGES
9 Mrinalini Kakroo
LINUX OVERVIEW
• The Linux operating system is a set of programs that links the computer and the end
user.
• Linux is one of the most outstanding examples of open-source and
free software
• KEY FEATURES
1. Free
2. Open source
3. Portable
4. Flexible
5. Multi-tasking
10 Mrinalini Kakroo
?WHY USE LINUX
• It is an open-source OS which gives a great advantage to the
programmers as they can design their custom operating
systems.
• Companies like Google, Amazon, and Facebook use Linux to
protect their servers as it is highly reliable and stable.
• Above all you don’t have to pay for software and server
licensing to install Linux, it’s free, and you can install it on as
many computers as you want.
• It’s a completely trouble free operating system and doesn’t
have an issue with viruses, malware and slowing down your
computer.
11 Mrinalini Kakroo
ADVANTAGES &DIS-ADVANTAGES
Mrinalini Kakroo
12
LINUX ARCHITECTURE
Mrinalini Kakroo
13
SHELL (1)
• A shell is a type of computer program called a command-line interpreter
that lets Linux and Unix users control their operating systems with
command-line interfaces. Shells allow users to communicate efficiently and
directly with their operating systems.
• There are two main types of shells: Command Line Shell and Graphical
User Interface (GUI) Shell.
• A Command Line Shell is a text-based interface where users interact with
the operating system by typing commands using a keyboard. The shell
interprets the commands and executes them, displaying the output on the
screen.
• A GUI Shell is a visual interface where users interact with the operating
system using graphical icons, windows, and menus. The shell provides a
user-friendly interface, making it easy to navigate and perform tasks.
14 Mrinalini Kakroo
SHELL (2)
1. The C Shell is a Unix shell with C-like syntax and interactive command-line
editing features. While it is less commonly used than shells like Bash or Zsh, it still
has a presence in Unix-like operating systems, including Linux.
2. The Korn Shell is another powerful and versatile command-line shell available on
Unix-like operating systems, including Linux. It incorporates features from both
the Bourne Shell (sh) and the C Shell (csh) and offers additional features like
command-line editing, spelling correction, and arithmetic expressions.
3. The Bourne Shell, often abbreviated as sh, is one of the earliest Unix shells, used
for scripting, which involves writing a series of commands in a file that can be
executed automatically.
4. The Bash is the most commonly used and default command-line shell in most
Linux distributions. It is a powerful and versatile shell that provides features such
as command-line editing, history management, and command completion.
15 Mrinalini Kakroo
COMMAND STRUCTURE (1)
• A command structure is a set of rules that defines the format and syntax of a
command in a computer system. It is a way to communicate with the
system and instruct it to perform a specific task.
• A command typically consists of the following components:
1. Command Name: The name of the command, which is a unique identifier
that tells the system what action to perform.
2. Options: Optional parameters that modify the behavior of the command.
Options are usually preceded by a hyphen (-) or a forward slash (/).
3. Arguments: The data or files that the command operates on. Arguments
can be files, directories, or other data.
4. Flags: Special characters that modify the behavior of the command. Flags
are usually preceded by a hyphen (-) or a forward slash (/).
16 Mrinalini Kakroo
COMMAND STRUCTURE (2)
• Command Syntax
• Types of Commands
1. Internal Commands: These are built-in commands that are part of the
shell.
2. External Commands: These are separate programs that are executed by
the shell.
3. Shell Scripts: These are scripts that contain a series of commands that are
executed by the shell.
17 Mrinalini Kakroo
COMMAND STRUCTURE (3)
• Command Structure Examples
1. Unix/Linux
2. Windows
3. MacOS
18 Mrinalini Kakroo
COMMAND STRUCTURE (4)
19 Mrinalini Kakroo
BASIC LINUX COMMANDS
1. sudo
Command: sudo
Description: Superuser Do. Allows a user to execute a command with superuser
privileges.
Example: sudo apt-get install firefox (installs Firefox browser with superuser
privileges)
2. ls
Command: ls
Description: List files and directories.
Options:
-l : displays a detailed list of files and directories
-a : displays all files and directories, including hidden ones
-d : displays only directories
Example: ls -l (displays a detailed list of files and directories)
3. pwd
Command: pwd
Description: Print Working Directory. Displays the current working directory.
Example: pwd (displays the current working directory)
4. mkdir
Command: mkdir
Description: Make Directory. Creates a new directory.
Options:
-p : creates parent directories if they don't exist
Example: mkdir myfolder (creates a new directory named "myfolder")
5. rmdir
Command: rmdir
Description: Remove Directory. Deletes an empty directory.
Example: rmdir myfolder (deletes the directory "myfolder" if it's empty)
6. rm
Command: rm
Description: Remove. Deletes files and directories.
20 Mrinalini Kakroo
PACKAGES IN LINUX
Install a Package
1. Open a terminal and type sudo apt-get install
<package_name> (replace <package_name> with the name of the package you want
to install).
2. Press Enter to execute the command.
3. If prompted, enter your password to authenticate the installation.
4. The package will be downloaded and installed.
Example: sudo apt-get install firefox
21 Mrinalini Kakroo
OPTION FOR DIRECTING THE COMMAND (1)
• In the command-line interface, the > and >> symbols are used to redirect
the output of a command to a file or another command. This is a powerful
feature that allows you to save the output of a command to a file, join to an
existing file, or even pipe the output to another command.
• The > Symbol:
The > symbol is used to redirect the output of a command to a file. If the file
does not exist, it will be created. If the file already exists, its contents will be
overwritten.
22 Mrinalini Kakroo
OPTION FOR DIRECTING THE COMMAND (2)
• The >> Symbol
The >> symbol is used to append the output of a command to a file. If the file
does not exist, it will be created. If the file already exists, the output will be
appended to the end of the file.
23 Mrinalini Kakroo
OPTION FOR DIRECTING THE COMMAND (3)
• Key Differences
>overwrites the file if it already exists.
>> appends to the file.
24 Mrinalini Kakroo
Cat COMMAND
25 Mrinalini Kakroo
Cat COMMAND OPTIONS
26 Mrinalini Kakroo
Compressing & Archiving Files (1)
27 Mrinalini Kakroo
Compressing & Archiving Files (2)
28 Mrinalini Kakroo
INTERNAL AND EXTERNALCOMMANDS (1)
• Internal Commands: Internal commands, also known as built-in commands, are commands that
are built into the shell itself. These commands are part of the shell's executable file and are
loaded into memory when the shell starts. Internal commands are typically used for shell
management, file management, and process management.
29 Mrinalini Kakroo
INTERNAL AND EXTERNALCOMMANDS (2)
• External Commands
External commands, also known as external executables, are commands that are stored
in separate executable files on the file system. These commands are typically used for
tasks that require more complex functionality than what is provided by internal
commands.
• Examples of External Commands
1. ls (list files and directories)
2. grep (search for patterns in files)
3. find (search for files based on various criteria)
4. vim (text editor)
5. gcc (C compiler)
• Characteristics of External Commands
They are stored in separate executable files on the file system.
They require an external executable file to be present on the system.
30 Mrinalini Kakroo
PIPELINING (1)
• Pipelining in Unix-like systems is a powerful feature that allows you to chain multiple
commands together, passing the output of one command as input to the next. This enables
you to create complex and efficient command-line workflows.
• Basic Pipelining Syntax:
command1 | command2
Here, the | symbol (called a "pipe") takes the output of command1 and feeds it as input
to command2.
• Suppose you have a file called example.txt and you want to count the number of lines in
it. You can use the wc (word count) command with the -l (lines) option. However, you
first need to display the contents of the file, which can be done using the cat command.
Instead of running these commands separately, you can use pipelining to combine them:
cat example.txt | wc –l. This command will display the contents of example.txt and pass it
to wc -l, which will count the number of lines and print the result.
• Pipelining is a powerful feature that can help you create complex command-line
workflows. With practice, you'll be able to combine multiple commands to achieve your
desired outcome efficiently.
31 Mrinalini Kakroo
.Expr command
The expr command is a built-in command in Unix-like operating systems,
including Linux and macOS, that evaluates an expression and prints the
result.
32 Mrinalini Kakroo
Echo Command (1)
The command itself is named after the concept of "echoing" or repeating back what is
given to it. In this case, echo takes an input (a string, variable, or command) and outputs
it to the standard output, usually the terminal screen.
33 Mrinalini Kakroo
Echo Command (2)
34 Mrinalini Kakroo
Echo Command (3)
35 Mrinalini Kakroo
Echo Command (4)
36 Mrinalini Kakroo
Using . and .. (1)
• In many programming languages, including Python, Java, and C++, the dot (.) and double dot
(..) are used to navigate through directories and access files or modules.
• Dot (.) notation:
The dot (.) represents the current working directory. It's often used to:
Access files or modules in the current directory.
Specify the current directory as the base for relative paths.
37 Vinod Sencha
Using . and .. (2)
• Double dot (..) notation:
The double dot (..) represents the parent directory of the current working directory. It's often used
to:
Move up one directory level.
Access files or modules in the parent directory.
38 Vinod Sencha
Using . and .. (3)
In file systems, the dot (.) and double dot (..) are used to navigate through directories. For
example:
. refers to the current directory.
.. refers to the parent directory.
../ refers to the parent directory of the parent directory (i.e., two levels up).
39 Vinod Sencha
.Ways for signing off from Linux
40 Mrinalini Kakroo
Ping, Man and help command (1)
41 Mrinalini Kakroo
Ping, Man and help command (2)
ping command options
The ping command has several options that can be used to customize its behaviour and
gather more information about the network connection. Here are some common options:
1. -c count: Specifies the number of packets to send.
Example:
ping -c 5 google.com
This command sends 5 packets to google.com.
2. -i interval: Specifies the interval between packets in seconds.
Example:
ping -i 2 google.com
This command sends packets to google.com with a 2-second interval between each packet.
3. -l preload: Specifies the number of packets to send initially.
Example:
ping -l 3 google.com
This command sends 3 packets to google.com initially, and then continues to send packets
until interrupted.
4. -n: Specifies that the output should only display numerical addresses, without resolving
hostnames.
ping -n google.com
This command displays the IP address of google.com instead of the hostname.
5. -q: Specifies quiet output, only displaying the summary at the end.
Example:
ping -q google.com
This command sends packets to google.com and only displays the summary at the end,
without showing each packet's response.
6. -s packetsize: Specifies the packet size in bytes.
Example:
ping -s 1024 google.com
This command sends packets of size 1024 bytes to google.com.
42 Mrinalini Kakroo
Ping, Man and help command (3)
The man command is used to display the manual for a specific command, function, or
system call. It provides detailed information about the usage, options, and syntax of a
command.
43 Mrinalini Kakroo
Ping, Man and help command (4)
The help command is used to display a list of available commands or to get help on a specific
command. It's often used to get a quick overview of the available commands and their usage.
Syntax: help [command_name]
44 Mrinalini Kakroo
Combining the commands(1)
• Executing commands one after the other in a command line is a regular
activity for a Linux administrator. But, by doing so, we may face the
following issues:
• The first command can take a long time to complete – one has to wait until
then to run the second command
• We may miss a particular command when multiple commands are run one-
by-one
• We may misspell a particular command, which may lead to unintended
consequences
• It’s time-consuming and annoying to run multiple commands one-by-one
• To prevent such situations and obtain the expected result, we can combine
and execute multiple commands in the command line.
45 Mrinalini Kakroo
Combining the commands(2)
• The “;” operator executes all commands regardless of whether the previous ones
failed or not.
46 Mrinalini Kakroo
Combining the commands(3)
• The “||” or OR operator executes the second command only if the
precedent command returns an error.
• {} is used for command grouping, where multiple commands are treated as a single
command.
47 Mrinalini Kakroo
File permissions and changing the access rights (chmod).(1)
48 Mrinalini Kakroo
File permissions and changing the access rights (chmod). (2)
Permissions are represented using a three-digit code, where each digit represents
the permissions for the owner, group, and other users, respectively. Each digit is
a sum of the following values:
•r (read): 4
•w (write): 2
•x (execute): 1
For example, the permission rwxr-x can be broken down as follows:
•rwx (owner): 4 (read) + 2 (write) + 1 (execute) = 7
•r-x (group): 4 (read) + 0 (write) + 1 (execute) = 5
•r-x (other): 4 (read) + 0 (write) + 1 (execute) = 5
49 Mrinalini Kakroo
File permissions and changing the access rights (chmod). (3)
The chmod command is used to change the permissions of a file or directory. There are two ways
to use chmod:
1.Symbolic notation: Uses letters to represent permissions.
2.Numeric notation: Uses numbers to represent permissions.
Symbolic Notation
•u (owner), g (group), or o (other) to specify the user type.
•+ (add), - (remove), or = (set) to specify the operation.
•r (read), w (write), or x (execute) to specify the permission.
Examples:
•chmod u+x file - adds execute permission for the owner.
•chmod g-w file - removes write permission for the group.
•chmod o=r file - sets read-only permission for other users.
50 Mrinalini Kakroo
File permissions and changing the access rights (chmod).(4)
Numeric Notation
•Uses a three-digit code, where each digit represents the permissions for the
owner, group, and other users, respectively.
Examples:
•chmod 755 file - sets permissions to rwxr-x (owner: read, write, execute;
group: read, execute; other: read, execute).
•chmod 644 file - sets permissions to rw-r--r-- (owner: read, write; group:
read; other: read).
51 Mrinalini Kakroo
.vi editor and its basics: write a small paragraph using vi editor
• VI editor is a basic text editor that is an acronym of 6 visual editor' and was
originally written by Bill Joy in 1976.
• Basically, there are three types of editors available in UNIX; these are named as ‘ed’
‘ex’, and 'vi’
• The 'ed' is a line editor
• The 'ex' editor is an advanced version of 'ed' that is more user-friendly comparative to
'ed’.
• The 'vi' is a screen editor and compared to 'ed' or 'ex' it is quite better.
• The vi editor is the most popular editor in Linux. The current version is really
"vim", but to invoke it simply type "vi".
52 Mrinalini Kakroo
53 Mrinalini Kakroo
54 Mrinalini Kakroo
55 Mrinalini Kakroo
56 Mrinalini Kakroo