0% found this document useful (0 votes)
30 views

Linux

Uploaded by

Bindu Prasad GS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Linux

Uploaded by

Bindu Prasad GS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 38

AGENDA

• Introduction to Linux

• Linux File System

• Basic file commands

• File permissions

• VI editor

• Expression pattern

• Process Management

• Cron Jobs

• Role of Linux in Cloud Computing and DevOps


Introduction to Linux
• The Linux Operating System is a type of operating system that is similar to Unix, and it
is built upon the Linux Kernel.

• It was created by a person named Linus Torvalds in 1991.

• The Linux Kernel is like the brain of the operating system because it manages how the
computer interacts with its hardware and resources.

• The Linux Kernel is combined with a collection of software packages and utilities, which
are together called Linux distributions. ( Ubuntu,Debian,openSUSE etc)

• These distributions make the Linux Operating System ready for users to run their
applications and perform tasks on their computers securely and effectively.

• Linux distribution is an operating system that is made up of a collection of software


based on Linux kernel or you can say distribution contains the Linux kernel and
supporting libraries and software.
Architecture of Click icon to add picture

Linux
 Kernel : is the core of the Linux based
OS. Different types of the kernel are:
Monolithic Kernel, Hybrid Kernels ,
Exo Kernels , Micro Kernels.

 System libraries : act as an interface


between applications and the kernel,
providing a standardized and
efficient way for applications to
interact with the underlying system.

 Hardware Layer : it encompasses all


the physical components of the
computer , such as RAM(Random
Access Memory),HDD(Hard Disk
Drive),CPU(Central Processing
Unit),and input/output devices.
 Shell : is the user interface of the Linux OS. It allows users to interact with the system by
entering commands , which the shell interprets and executes The shell serves as a bridge
between the user and the kernel , forwarding the user’s requests to the kernel for
processing.
 System Utility : these utilities perform tasks such as installing software , configuring
network settings, monitoring system performance , managing users and permissions ,
and much more.

Advantages of Linux
 Linux is an open-source operating system.
 Linux is more secure than any other OS.
 It maintains the privacy of the user.
 It is fast and easy to install from the web.
 The software updates in Linux are easy and frequent.
 Linux is a multi-programming, multi-user operating system, it means the same system
can be used by different users with different access rights and simultaneously many
applications can be run on it.
 Linux can work on different types of hardware, so Linux is portable.
Differences between Linux and Windows
LINUX WI N D OWS

• Linux is an open source OS. • Windows are not open source OS.

• Linux is free of cost. • It is costly.

• Linux provides more security than • It provides less security than Linux.
windows.
• Administrator user has all
• Root user is the super user and has all administrative privileges of computers.
the administrative privileges.
• While there is back slash is used for
• There is forward slash is used for Separating the directories.
Separating the directories.
Linux File System
• The Linux file system organizes data and files on a storage device, providing a
structured way to manage information.

• The Linux File Hierarchy Structure or the Filesystem Hierarchy Standard (FHS) defines
the directory structure and directory contents in Unix-like operating systems.
The /boot directory in a Linux file system contains the files needed to start the boot process of
the operating system.
Linux Directory Structure
In Linux/Unix operating system everything is a file even directories are files, files are files, and
devices like mouse, keyboard, printer, etc are also files.

We know that in a Windows-like operating system, files are stored in different folders on
different data drives like C: D: E: whereas in the Linux/Unix operating system files are stored
in a tree-like structure starting with the root directory.
Basic File Commands
• ls (lists the files and directories in the working directory)

Syntax :: ls [options] file_name/directory_name

ls -l : displays detailed information about files and directories

ls -a : includes hidden files and directories

ls -t : displaying the most recently modified ones first

ls -r : reverse order of the string

ls -S : sort files and directories by their size

ls -R : list files and directories recursively, including subdirectories

-rw-r--r-- 1 Dell 197121 316 June 24 22:09 fibonacci.txt


1st field : File type :: - (normal file),d (directory file),s (socket file),l(link file)
File permissions :: read,write,execute for user(root),group,others
Number of links
Owner :: owner of the file
Group :: group of the file
Size :: size in bytes
Last modified date and time
File name

• pwd ( prints the current working directory)

• mkdir ( creates new directory)


Syntax :: mkdir directory_name

• cd ( used to navigate between directories)


Syntax :: cd directory_name
cd / : changes to the root directory
pwd : present working directory/current directory
cd dir1/dir2/dir3 : to move into sub-directories
cd ~ or cd : changes to home directory from any directory
cd .. : which is used to move to the parent directory of current
directory , or the directory one level up from the current directory.
“ . . “ represents parent directory
• rmdir ( to delete permanently an empty directory )
Syntax : : rmdir directory_name
rm file_name : to remove single file name
rm file1 file2 : to remove multiple files
rm -i file_name : interactive deletion ( asks for confirmation for deletion )
rm -f file_name : removes the file forcefully
rm -r/-R directory_name : delete all the files and sub-directories recursively of
the parent directory

• cp ( copy-paste and cut-paste files )


Syntax :: cp source_file destination_file
cp -i source_file destination_file ( confirmation )
cp src_file1 src_file2 src_file3 dest_directory_name/ ( copy multiple files to
directory )
cp -R source_directory dest_directory ( copy files between two directories )

• mv 1) Renaming a file or directory.


2) Moving a file or directory to another location.
Syntax : : mv source_file_name destination_file_name : to rename a file
mv source_file_name destination_path : to move a file

• touch (creates an empty file)


Syntax :: touch filename
• cat ( create a file with content and also display the content )
syntax : : cat > file_name
type the content for the file if not press ctrl+D
cat file_name ( displays the content )
cat -n file_name : to view contents of the file with line numbers
cat file1 >> file2 : appending the content of file1 to the end of file2
tac file_name : displaying the content in reverse order
cat >> filename ( appending the content to the same file )

• clear (clear the terminal screen)

• man (user manual for any command)


Syntax :: man command_name

• echo (used to print content in the terminal)


Syntax :: echo “content”

• history ( to lists commands used )

• wget ( allows to download files from the internet )


• whoami ( system's username )
• who ( users logged into system )
• who am i ( current users info )
• sort ( used to sort a file, arranging the records in a particular order )
syntax : : sort filename
sort -r filename(reverse order)
sort -n filename(numeric sort)
sort -c filename(checks whether a file is sorted or not)

• df -h ( details of file system, memory usage )


• du -h ( disk space for each directory)
• free -h( total memory used which includes swap also )
• top ( view of the running system )
Syntax : : top ( it gets refreshed after ever 3s )

• wc, word count ( prints the count of each word, lines etc )
Syntax : : wc filename
number_of_lines number_of_words number_of_characters filename
(wc -l fname ) (wc -w fname) (wc -c fname)

• | (pipe ) :: output the result of one command as input to another command


ls -l | grep word/string filename
• less (to read the starting content from a very big data )
Syntax : less file_name
and press down arrow key ( to view the content downwards )
• head ( it outputs the first part of the file (usually 10lines )
Syntax : head file_name
head -nhow_many_lines filename
• tail ( it outputs the last part of the file )
Syntax : tail -nhow_many_lines file_name
File Permissions
 Linux is a multi-user operating system , so it has security to prevent people from accessing
each others confidential files.
 How to check the permissions of files in Linux?

ls -l

1st character :: File type -- - (normal file),d (directory file),s (socket file), l (link file)

2nd character :: File permissions – read , write , execute for user(root), group ,
others

3rd character :: Number of links

4th character :: Owner of the file

5th character :: group of the file

6th character :: size in bytes

7th character :: last modified date and time of the file

8th character :: File name


Three permissions groups in Linux
1. Owners :: these permissions apply exclusively to the individuals who own the files or
directories.
2. Groups :: permissions can be assigned to a specific group of users , impacting only
those within that particular group.
3. Others/all Users :: these permissions apply universally to all users on the system.

--- --- ---


rwx rwx rwx
user group others
 Three kinds of file permissions of Linux
‘ r ’ :: read the file’s content
‘ w ‘ :: write or modify the file’s content
‘ x ‘ :: execute a programmable file

‘ + ‘ :: add the permissions


‘ – ‘ :: remove the permissions
‘ = ‘ :: set permissions to the specified values
read (4) , write(2) , execute (1) [octal representations]

• Users (u) :: the user permissions apply only to the owner of the file or directory , they will
not impact the actions of other users.
• Group (g) :: the group permissions apply only to the group that has been assigned to the
file or directory , they will not affect the actions of other users.
• Others (o) :: the other permissions apply to all other users on the system.
• All (a) :: all three permissions ( owner , groups , others)

 How to change permissions in Linux


Syntax :: chmod permissions filename/directory_name

chown :: to change the owner of files and directories


chown username filename
chown username:groupname filename

chgrp :: to change the group ownership of files and directories


chgrp groupname filename
VI Editor
• VI Editor , we can edit an existing file or create a new file from scratch.

• How to open VI editor

vi filename , press esc key

enter into insert_mode (press I )

type the content , press esc key

type :wq and hit enter ( w for saving the file , q to quit the file )

• Modes of operation in the VI editor

Command Mode

Insert Mode

Escape Mode
Regular Expressions
• Regular expressions are special characters or set of characters that help us to search
for data and match the complex pattern.
GREP ( Global Regular
Expression Print )
It is a powerful tool used for searching and manipulating text patterns
within files.
 It’s a command-line utility in Unix and Unix-like operating systems used
for searching within files for lines that match a regular expression and
printing them to the standard output.

Syntax :: grep options pattern file_name

grep -c ( count of lines that match a pattern )

grep -h ( display the matched lines, but do not display the


filenames )
grep -i ( ignores case for matching)
grep -l ( displays list of filenames only )
grep -n ( displays the matched lines and their line numbers )
grep -v ( prints out all the lines that do not matches the pattern )
grep -w ( match whole word/particular word only )
grep -o (print only the matched parts of a matching line , with each such part on a separate
line )

Example :: cat > file_name


unix is great os.unix was developed in Bell labs.
learn operating system.
Unix linux which one you choose.
uNix is easy to learn.unix is multiuser os.Learn unix.unix is powerful.
SED ( Stream Editor )
 SED command in UNIX stands for stream editor and it can perform lots of functions on
file like searching , find and replace, insertion or deletion.

 Though most common use of SED command in UNIX is for substitution or for find and
replace. Syntax :: sed options [script] [inputfile]

Example :: cat > file_name

unix is great os.unix is opensource.unix is free os.

learn operating system.

unix linux which one you choose.

unix is easy to learn.unix is multiuser os.Learn unix.unix is powerful.


Process Management
 What is a Process ?
Whenever you issue a command in Unix , it creates , or starts , a new process.
When you tried out the ls command to list the directory contents , you started a
process.
A PROCESS , in simple terms , is an instance of a running program.
 The operating system tracks processes through a five-digit ID number known as the
PID or the PROCESS ID. Each process in the system has a unique PID.
 When you start a process (run a command) , there are two ways you can run it :
1. FOREGROUND PROCESSES 2. BACKGROUND PROCESSES
FOREGROUND PROCESSES :: By default, every processes that you start runs in
foreground. It gets its input from the keyboard and sends its output to the screen.
Disadvantage : While a program is running in the foreground and is time-consuming, no
other commands can be run ( start any other processes ) because the prompt would not
be available until the program finishes processing and comes out.
Example :: $ls file_name
BACKGROUND PROCESSES :: A background process runs without being connected to your
keyboard.
Example :: $ls file_name & ( once done press the enter key )
Advantage : we can run other commands , you do not have to wait until it completes to start
another!

 Listing running processes :: to check the running processes , run the command ps
( process status ) or ps –f ( displays detailed info )
UID : USER ID that this process belongs to ( the person who is running it )
PID : process ID
PPID : parent process ID
C : CPU utilization of process
STIME : process start time
TTY : terminal type associated with the process
TIME : CPU time taken by the process
CMD : the command that started this process

TTY : Teletypewriter originally and also means any terminal on Linux/Unix systems.
PTS : stands for the pseudo-terminal slave
PARENT AND CHILD PROCESSES ::
processes are organized in a hierarchical manner where each process, except for the very first
process called the "init" process, has a parent process.
When a process creates another process, the one that initiated the creation becomes the parent,
and the new process becomes its child.
For example, imagine you start a terminal session. The terminal process becomes the parent
process.
Now, if you run a command within that terminal, say, open a text editor, the text editor process
becomes a child process of the terminal.
If you then decide to run another command, say, a file compression tool from within the text
editor, that compression tool process becomes a child process of the text editor process and a grandchild
process of the terminal.
ZOMBIE AND ORPHAN PROCESSES :: A zombie process is a terminated process that has
completed its execution, but its entry still remains in the process table because its parent
process hasn't yet read its exit status.
Essentially, it's a dead process that is waiting for its parent process to
acknowledge its termination and retrieve its exit status.
An orphan process is a process whose parent has terminated or finished while
the child process is still running.
When the parent process ends before the child, the orphaned child process
gets re-parented to the init process (PID 1), which becomes its new parent.

DAEMON PROCESSES :: a daemon is a process that runs in the background, usually waiting
for something to happen that it is capable of working with.
For example, a printer daemon waiting for print commands.
Cron Jobs
A cron job is a task created using cron , a tool for scheduling and
automating future tasks on Unix-like operating systems.
With cron jobs, system administrators can automate maintenance
, disk space monitoring , and backups at regular intervals.
They are also useful for web developers as they can set up
simultaneous cron jobs at different intervals to back up a site ,
check for broken links , and clear its cache.
Each cron job is stored in a cron table or “crontab” . The files
themselves are usually stored in a directory like
/var/spool/cron/crontabs , with one file per user , named after
their username.
• Structure of a Cron expression
* * * * * command – to – execute
- - - - -
Day of the week (0-7) (Sunday =0 or 7)

Month of the year (1-12)

Day of the month (1-31)

Hour (0-23)

Minute (0-59)

Crontab Guru is an easy-to-use editor for crontab schedules, offering a straightforward


Interface for generating cron schedule expressions ( CRONTAB GURU )
Role of Linux in Cloud
Computing and DevOps
Advantages of Linux in DevOps

You might also like