Linux ppt
Linux ppt
1
Agenda
What is LINUX?
Why LINUX?
Introduction to LINUX.
Basic Commands
VIM Commands
Grep Commands
SED commands
2
What is Linux
3
Why Linux?
Open Source: The code is public, so anyone can see how it works, improve it, or fix issues.
Security: Linux is much less prone to viruses and malware than other operating systems because of its robust
design and strict user permissions.
Performance: Linux is lightweight and fast. It can run smoothly even on older computers.
Customizability: You can tweak and modify almost everything in Linux to suit your needs.
Reliability: Linux rarely crashes, making it ideal for servers, businesses, and critical systems.
Privacy and Control: No spying or telemetry by default. You control what your system does.
Versatility: Runs on almost anything: PCs, servers, smartphones, Raspberry Pis, smart TVs, supercomputers
—you name it!
Cost-Effective for Businesses: Companies use Linux for servers and systems because it’s free, reliable, and
highly scalable.
Learning Opportunity: Linux helps you learn how computers work. It’s a great skill for careers in IT,
programming, or cybersecurity.
4
Linux Architecture
1. Kernel
The core of the Linux operating system, responsible for managing
system resources such as CPU, memory, and hardware.
Provides an interface between hardware and software.
2. System Libraries
A set of functions and routines that applications can call to interact
with the kernel.
3. System Utilities
Basic tools and services that allow users and applications to interact
with the operating system.
Hardware
The physical components that the kernel directly manages, such as
CPU, memory, disks, and peripherals.
5
Basic Commands of Linux
6
ls – Linux shell
lists directory contents of files and directories.
˃Syntax :ls [option] [file/directory]
Options Description
-l known as a long format that displays detailed information about
files and directories.
-a Represent all files Include hidden files and directories in the
listing.
-t Sort files and directories by their last modification time,
displaying the most recently modified ones first.
-r known as reverse order which is used to reverse the default order
of listing.
-S Sort files and directories by their sizes, listing the largest ones
first.
-R List files and directories recursively, including subdirectories.
-i known as inode which displays the index number (inode) of each
file and directory. 7
pwd - print/present working directory
prints the path of the current working directory, starting from the root.
˃ Syntex: pwd
9
mkdir : - make directory
create multiple directories at once as well as set the permissions for the
directories
Syntax: mkdir [options...]
[directory_name]
$ mkdir -p first/second //creating a directory
hierarchy without errors . parent
directory/subdirectory
10
cat
allowing users to view, concatenate, create, copy, merge, and manipulate
file contents.
Syntax: cat [OPTION] [FILE]
11
continue
$ cat heni.txt ans.txt //concatenate two file
12
wc - words count
to find out number of lines, word count, byte and characters count in the
files specified in the file arguments.
13
echo
users to display lines of text or strings that are passed as arguments.
$ echo “hello” > helo.txt // write the content in a file without opening that file
$ cat helo.txt
14
touch
to create a file without any content.
15
cp - copy
creates a copy of the `source_file` at the specified `destination`.
16
mv - move
generally used for renaming the files in Linux.
17
rm - remove
to remove objects such as files, directories, symbolic links and so on from the file system like UNIX.
2.$ rm --version // display the version of rm which is currently running on your system.
18
rmdir – remove directory
for removing empty directories.
19
cd – change directory
to change directories in Linux
Syntax: cd [directory]
Code:
$cd filename //change directory
$ cd first/second // move
inside a directory from a directory.
20
file permission commands (chmod)
to modify the read, write, and execute permissions of files or directories
File Permissions
•r: Read permission (value = 4)
•w: Write permission (value = 2)
•x: Execute permission (value = 1)
Sr. Chmod operator & Description
No.
1 +: Adds the designated permission(s) to a file or
directory.
2 -: Removes the designated permission(s) from a file or
directory.
3 = : Sets the designated permission(s).
21
Vim commands
23
Introduction to Vim
• VIM is a highly configurable text editor used for efficient text editing in Linux.
Modes in VIM:
• Normal Mode: Default mode for navigating and manipulating text.
• Insert Mode: Used for text input.
• Command Mode: For executing commands.
• Visual Mode: Can manipulate text visually
24
Vim commands
25
grep commands
28
Introduction
The command used to search and print lines from a specified file that contain a specific
pattern or word is the grep command.
Grep stands for Global Regular Expression Print
Basic Syntax of grep Command: grep [options] 'pattern' filename
• pattern: The word, string, or regular expression you want to search for.
• filename: The file in which to search the pattern.
• options: Optional flags that modify the behavior of grep (e.g., case-insensitive search,
line numbers, etc.)
29
Grep commands
30
Sed commands
32
Introduction
Sed stands for Stream Editor.
It is a powerful tool used for text manipulation and stream editing.
Commonly used for searching, replacing, inserting, deleting, and transforming text in files or input streams.
Syntex : sed [OPTION] 'COMMAND' FILE
OPTION: Specifies how sed should operate (e.g., -i for in-place editing).
COMMAND: The action you want to perform (e.g., substitution, deletion).
FILE: The file or input stream where the sed command will be applied.
33
Sed commands
34
Awk commands
36
Introduction
AWK is a powerful text-processing language used in Unix-like operating
systems.
Basic Syntax: awk 'pattern {action}' filename
37
Awk Commands
awk 'BEGIN {print "Start of the file" } { print $0 } END { print "End of the file" }' filename
awk -F',' '{ $1=""; sub(/^,/, ""); gsub(",", "|"); print }' filename
38
Cut commands
40
Introduction
`cut` is a command-line utility for extracting sections from lines of input files in
Unix-like operating systems.
Basic Syntax : "cut [options] filename"
41
Cut Commands
cut -d',' -f2 filename` : Extracts the second field using a comma (`,`) as the delimiter.
`cut -d'.' -f3 filename` : Extracts the third field using a dot (`.`) as the delimiter.
`cut -c1-20 filename` : Displays characters from position 1 to 20 of each line in the file.
`cut -c1 filename` : Displays the first character of each line in the file.
`cut -d':' -f1,3 filename` : Extracts the first and third fields using colon (`:`) as the delimiter.
cut --complement -d',' -f1,2 filename` : Displays all fields except the first and second.
`cut -d'l' -f2 filename` : Extracts the second field using the character `l` as a delimiter.
`cut -d':' --output-delimiter='|' -f2 filename` : Extracts the second field and replaces the delimiter with a pipe (`|`).
42
Shell Scripting
44
What is Shell Scripting?
Definition: A program written for the shell to automate tasks.
Executes sequential commands.
Works with various shells (Bash, Zsh, Ksh).
Integrates with Linux utilities.
Need for Shell Scripting
• Efficiency: Automates routine tasks, reduces manual work.
• Productivity: Enhances system administration processes.
• Cost-Effective: No need for additional software.
• Example: Automating daily system health checks.
45
SHELL SCRIPTING
Operating System Layers:
• Hardware: The core physical components of the
system.
• Kernel: Manages hardware resources, file
systems, and multitasking.
• Shells: Interface between users and the OS
(e.g., sh, ksh, csh).
• Utilities: Command-line tools for various
operations (e.g., ls, awk, cat).
46
SHELL SCRIPTING
Use cases of Shell Scripting
• System Automation
o Backups and file management.
o Process monitoring.
o Scheduled cron jobs.
• Networking:
o Automated diagnostics
o Configuration management.
47
SHELL SCRIPTING
Advantages of Shell Scripting
• Quick Development: Easy to write and execute.
• Integration: Works with built-in Linux commands.
• Portability: Run across UNIX/Linux distributions.
• Scalability: Can be adapted for complex tasks.
Disadvantages of Shell Scripting
• Complexity: Hard to maintain large scripts.
• Error-Prone: Lacks robust debugging tools.
• Security Risks: Improper use can expose vulnerabilities.
• Performance: Slower than compiled languages.
• Example: Pitfalls of using unverified scripts.
48
SHELL SCRIPTING
Difference Between Shell Scripting and Higher-Level Scripting Languages
Feature Shell Scripting Higher-Level Languages
(Python, Perl)
Speed Fast for small tasks Slower due to interpretation
overhead
Ease of Use Simple commands Complex syntax but more
features
Portability UNIX/Linux specific Cross-platform
49
SHELL
Basic commands and Symbols
SCRIPT COMMANDS
String Comparison
#: Used to add comments to the script (ignored by the interpreter).
str1 = str2: Checks if string str1 is equal to string str2.
echo: Prints data to the terminal.
str1 != str2: Checks if string str1 is not equal to string str2.
read: Reads input from the user.
Numeric Comparison
$var: Used to access the value of a variable.
n1 -eq n2: Checks if number n1 is equal to number n2.
$#: Represents the number of arguments passed to the script.
n1 -ne n2: Checks if number n1 is not equal to number n2.
$*: Represents all arguments passed to the script.
n1 -gt n2: Checks if number n1 is greater than number n2.
$1, $2, ... $9: Represent the first, second, up to ninth arguments
passed to the script. n1 -ge n2: Checks if number n1 is greater than or equal to
if-else: Performs conditional execution based on a given condition. number n2.
n1 -lt n2: Checks if number n1 is less than number n2.
if-elif-else: Handles multiple conditions.
;: Used to end the statement and continue writing another n1 -le n2: Checks if number n1 is less than or equal to
command on the same line. number n2.
$?: Stores the return value of the last executed command. 0 usually Logical Operators
indicates success, while non-zero values usually indicate an error. ||: Performs logical OR operation. Returns true if either or both
conditions are true.
&&: Performs logical AND operation. Returns true only if both
conditions are true.
50
Thank You
51