Linux
Linux
systems.
It uses the SMB (Server Message Block) protocol to enable interoperability between different operating systems in a
network.
Key Points:
Helps Linux act as a file/print server for Windows clients.
Supports network browsing and authentication.
Commonly used in mixed-OS environments (Linux + Windows).
syntax of the case statement in shell programming (bash):
case expression in
pattern1)
commands ;;
pattern2)
commands ;;
pattern3)
commands ;;
*)
default commands ;;
esac
Important points:
case starts the block and esac ends it ("case" spelled backward).
;; ends each pattern’s command block.
* is the default case (like else).
Here’s a short, summarized note:
Shell environment refers to the collection of settings, variables, and configurations that control how a shell behaves and
interacts with the system and the user.
It includes environment variables (like PATH, HOME, USER), shell options, and configurations that affect command
execution and scripting.
commands used to create files in Linux
cat > filename – Creates a new file and lets you add content.
touch filename – Creates an empty file (or updates the timestamp if the file exists).
vi filename – Opens the vi editor to create and edit a new file.
difference between home directory and working directory in Linux:
Home Directory:
It is the default directory where a user is placed after logging into Linux.
Example: /home/username
It stores the user's personal files and settings.
Working Directory:
It is the current directory where you are working at any moment.
You can move (change) the working directory using the cd command.
You can check it using the pwd command.
Linux File System
Introduction
In Linux, the file system plays a crucial role in organizing and managing data on physical drives. Each physical drive can
be divided into multiple partitions, and each partition can host one file system.
A file system is:
A logical structure used by the operating system to manage how data is stored and retrieved.
Composed of methods and data structures to keep track of files.
Used to organize and store files efficiently.
2. Super Block
Describes the state and configuration of the file system.
Contains critical metadata such as:
Total size of the partition
Block size
Maximum number of files
Pointers to free blocks and free inodes
Number of allocated/free inodes
Size and structure of inode tables
Inode number of the root directory
Crucial for accessing files; hence, it's backed up in multiple areas on the disk.
4. Data Block
Contains the actual content of the files.
Starts immediately after the inode table.
Stores:
User files (text, media, code, etc.)
Special files (device files, symbolic links, directories)
Each block is allocated to one file only, and once deleted, the block becomes reusable.
➤ XFS
Developed for high-performance and high scalability.
Offers near-native I/O performance even across multiple storage devices.
Conclusion
Linux supports a variety of file systems, each optimized for different use cases such as speed, reliability, scalability, or
clustering. The ext4 remains the most commonly used, but others like XFS, JFS, and OCFS2 serve critical roles in
enterprise and performance-driven environments.
Here's a well-structured and expanded version of your notes on Types of Shells in Linux, ideal for exams, assignments, or
presentations:
🧪 Example:
#!/bin/bash
name="Alice"
echo "Hello, $name!"
Output:
Hello, Alice!
In a shell script, instructions are executed sequentially, one after another. However, in some cases, you may need to
execute different sets of instructions based on certain conditions. This is where branching statements come into play.
They allow the script to make decisions and control the flow of execution.
Linux has following types of branching statements:
The if statement
The case statement
Linux Shell supports following forms of if statement (Branching Statements)
If….fi statement
if else... fi statement
if...elif...else... fi statement
1. The if statement
The if statement checks whether a condition is true. If the condition is true, a set of commands is executed. If the
condition is false, no action is performed.
Syntax:
if [ condition ]
then
statement-block
fi
The condition can be any expression that returns true (0) or false (non-zero).
The statement-block is executed only if the condition is true.
Example:
#!/bin/bash
a=10
b=10
if [ $a -eq $b ]
then
echo "a and b are equal"
fi
Output:
a and b are equal
if [ $a -eq $b ]
then
echo "a and b are equal"
else
echo "a and b are not equal"
fi
Output:
a and b are not equal
if [ $a -gt $b ]
then
echo "$a is greater than $b"
elif [ $a -lt $b ]
then
echo "$a is less than $b"
else
echo "$a and $b are equal"
fi
Output:
10 is less than 20
4. Nested if statements
A nested if statement is used when one condition must be checked inside another condition. You can use an if inside the
true or false block of another if statement.
Syntax:
if [ condition1 ]
then
if [ condition2 ]
then
statement-block
else
statement-block2
fi
else
statement-block3
fi
Example:
#!/bin/bash
a=20
b=10
if [ $a -gt $b ]
then
if [ $a -gt 50 ]
then
echo "$a is greater than 50"
else
echo "$a is less than or equal to 50"
fi
else
echo "$a is less than $b"
fi
Output:
20 is greater than 50
if test $a -gt $b
then
echo "$a is greater than $b"
else
echo "$a is not greater than $b"
fi
Output:
10 is not greater than 20
case $op in
+)
result=$(($a + $b))
echo "$a + $b = $result"
;;
-)
result=$(($a - $b))
echo "$a - $b = $result"
;;
\*)
result=$(($a * $b))
echo "$a * $b = $result"
;;
/)
result=$(($a / $b))
echo "$a / $b = $result"
;;
*)
echo "Invalid operator"
;;
esac
Example Input:
Enter two numbers
10 5
Enter an operator (+, -, *, /)
+
Output:
10 + 5 = 15
Conclusion
Key Points:
if statements allow decision-making in a script.
The test command is used for evaluating expressions (e.g., comparing integers, strings, or checking file conditions).
Use if...then...fi, if...else...fi, and if...elif...else...fi structures to control the flow based on conditions.
Nested if statements help in more complex decision-making.
The case statement is useful for multi-way branching and matching patterns.
Domain Name System (DNS)
The Domain Name System (DNS) is an essential component of the Internet infrastructure, often referred to as the
"phonebook of the Internet". DNS is responsible for translating human-readable domain names (such as example.com)
into machine-readable IP addresses (like 198.105.232.4).
Purpose of DNS
Human-friendly names: Humans access websites through domain names (e.g., www.example.com), which are easier to
remember than numeric IP addresses.
Machine-readable addresses: The Internet works based on IP addresses, so DNS servers are used to convert domain
names into IP addresses, allowing browsers and other services to connect to websites.
Components of DNS
DNS operates through various components, including:
Domain Names: These are the names we type in the browser, such as www.example.com.
IP Addresses: These are the numeric addresses used by machines to locate each other, like 198.105.232.4.
DNS Records: These are entries in DNS databases that define various attributes of a domain, such as:
A records: Maps domain names to IPv4 addresses.
AAAA records: Maps domain names to IPv6 addresses.
MX records: Specifies mail servers for a domain.
CNAME records: Alias for a domain name.
NS records: Specifies the name servers for a domain.
DNS Query Process:
When a user wants to access a website, their computer sends a query to a DNS server.
The DNS server responds with the IP address corresponding to the domain name.
vi Editor Overview
The vi editor is a screen-oriented text editor that is widely used in Linux and Unix systems. It was developed by Bill Joy at
the University of California, Berkeley. The vi editor is an interactive, full-screen editor that allows users to create, edit, and
view files.
Key Features of vi Editor:
Widely used: Available in nearly all Linux and Unix distributions.
Multiple file support: Capable of handling multiple files at the same time (these are called buffers in vi terminology).
Efficient text manipulation: Allows operations like cutting, copying, pasting, searching, replacing text, importing/exporting
text, and even spell-checking.
Not just for text files: vi is also used for composing emails and editing command-line scripts.
Modes in vi Editor
The vi editor operates in three main modes:
Command Mode (Default Mode)
Insert Mode (Input Mode)
Line Mode (Ex Mode)
Each mode serves a different function, and understanding how to switch between them is crucial for efficient use of vi.
Advanced vi Features
Searching for Text:
/text → Search forward for "text".
?text → Search backward for "text".
n → Move to the next occurrence of the search.
N → Move to the previous occurrence of the search.
Replacing Text:
:s/old/new/g → Replace "old" with "new" globally in the line.
:%s/old/new/g → Replace "old" with "new" globally in the entire file.
Multiple Files (Buffers):
:e filename → Open a different file in vi.
:n → Switch to the next file (if multiple files are open).
:prev → Switch to the previous file.
:
Definition
Telnet refers to both:
The protocol used to connect to remote computers.
The command-line utility used to establish those connections.
It provides a bidirectional, interactive text-based communication facility between two computers.
Features
Remote Access:
Enables logging into a remote machine and controlling it via command-line interface.
The remote machine can be in the next room, city, or even a different country.
Cross-Platform Support:
Telnet clients are available on Windows, Linux, macOS, and other Unix-like operating systems.
Most network equipment (routers, switches) and operating systems that support TCP/IP come with a built-in Telnet server
or client.
Server Control:
Commonly used by network administrators to configure and control servers remotely.
Frequently used to test network services, debug servers, or connect to legacy systems.
Command Execution:
Allows execution of commands remotely as if entered directly at the remote terminal.
Requires login with a valid username and password.
Advantages
Simple to use and understand.
Lightweight protocol with low bandwidth consumption.
Useful for connecting to legacy systems that do not support modern remote access tools.
Disadvantages
Lacks security: Data, including usernames and passwords, is sent in plain text, making it vulnerable to interception.
No encryption: Unlike modern protocols like SSH, Telnet does not encrypt the session.
Mostly replaced by SSH (Secure Shell) for secure communication.
Here's a rearranged and expanded version of your notes on FTP (File Transfer Protocol), suitable for exam preparation:
Working of FTP
FTP uses the client-server model:
Client: initiates a request to connect to the server.
Server: responds and processes file operations.
FTP operates on two separate communication channels:
Command Channel: Used for sending control commands (e.g., login, change directory).
Data Channel: Used for transferring file data.
FTP Modes
Active Mode:
Client initiates connection to the server on port 21.
Server initiates the data connection back to the client.
Passive Mode:
Client initiates both command and data connections.
Works better with firewalls and NAT (Network Address Translation).
More secure and widely used in modern networks.
Disadvantages of FTP
Disadvantage Explanation
Data, including passwords, is transferred in plain text. Vulnerable to eavesdropping and MITM
Lack of Encryption
attacks.
Limited Compatibility Not all systems support FTP natively or securely.
No Multi-Session Support Cannot perform simultaneous large file transfers efficiently.
Size Limit Some FTP implementations limit file size to 2 GB.
Vulnerable to Brute Force Passwords can be guessed if not properly secured.
1. Processor (CPU)
Minimum Requirement:
A 400 MHz Pentium processor is typically the minimum for a Graphical User Interface (GUI) installation.
Linux can run on even older processors like the Intel 486, though this would be for very lightweight or minimal
installations.
Recommended:
A 32-bit processor (x86) is fine for basic applications.
A 64-bit processor (x86_64) is recommended for modern systems, especially if you plan to run virtual machines or
high-performance applications.
Special CPU Features:
For virtualization (e.g., using KVM), your CPU must support hardware virtualization technologies like:
Intel VT-x (Intel Virtualization Technology)
AMD-V (AMD Virtualization)
2. RAM (Memory)
Minimum Requirement:
Linux can run on as little as 24MB of RAM for ultra-minimal distributions or embedded systems.
1GB of RAM is generally the minimum for a GUI-based Linux distribution.
Recommended:
2GB–3GB or more for a smooth desktop experience.
More RAM is needed for running heavy applications, multiple users, or virtual machines.
2. Redirection Symbols
Symbol Purpose Description
> Output Redirection Overwrites file with command output
>> Output Redirection (Append) Appends command output to file
< Input Redirection Takes input from a file
<< Here Document (Input redirection) Multi-line input
2> Error Redirection Sends error messages to a file
2>> Error Redirection (Append) Appends error messages to a file
🔐
15marks
File Access Permissions in Linux
In Linux, file and directory access is controlled through a permission system. This system provides security and proper
access management in a multi-user environment. Every file and directory has defined permissions for the owner (user),
group, and others.
👥 Types of Ownership
User (u): The person who created the file. They are the owner.
Group (g): A group can contain multiple users. Members of the group can share file access.
Others (o): Any user who is not the owner or part of the group. This is sometimes referred to as "world".
📄Symbol
Types of Permissions
Permission Description
r Read Allows viewing the file’s contents or listing directory contents.
w Write Allows modifying file contents or adding/removing files in a directory.
x Execute Allows running the file as a program or entering a directory.
Each permission can be enabled (r, w, x) or disabled (-).
🔍 Viewing Permissions
Use the ls -l command to view file permissions:
ls -l filename
Example Output:
-rwxr-xr--
Breakdown:
- = regular file
rwx = permissions for user
r-x = permissions for group
r-- = permissions for others
📌
You can change file permissions using the chmod (change mode) command.
Syntax:
chmod [options] mode filename
🔠
In symbolic mode, letters and operators are used to assign or remove permissions.
Symbols
u = user (owner)
g = group
o = others
➕
a = all (user + group + others)
Operators
Symbol Action
+ Adds a permission
- Removes a permission
= Assigns and overwrites
1. uname Command
Purpose:
The uname command is used to display system information about the Linux operating system.
Syntax:
uname [options]
Common Options and Their Use:
Option Description
-a Displays all system information
-s Displays the kernel name
-n Displays the network node hostname
-r Displays the kernel release
-v Displays the kernel version
-m Displays the machine hardware name
-p Displays the processor type
-i Displays the hardware platform
-o Displays the operating system name
Example:
uname -a
Output:
Linux myhost 5.15.0-105-generic #115-Ubuntu SMP ... x86_64 GNU/Linux
Use in Practice:
To check the OS version and kernel details.
Useful for troubleshooting or system diagnostics.
2. hostname Command
Purpose:
The hostname command is used to display or set the name of the current host system.
Syntax:
hostname [new_name]
Common Uses:
Task Command Example
View the current hostname hostname
Set a new temporary hostname sudo hostname newname
View the full DNS domain name hostname -f
View the short hostname hostname -s
Note: Setting the hostname this way is temporary and will be reset after reboot unless changed in system config files (like
/etc/hostname).
Use in Practice:
Identify or modify the system's network name.
Helpful for network administration and SSH identification.
🌐 Apache Web Server (Expanded Notes)
🔷 Introduction
Apache (officially called Apache HTTP Server) is the most widely used web server software in the world.
It was developed by the Apache Software Foundation, with its first release in 1995.
Apache is open-source, free, and cross-platform (works on both Unix/Linux and Windows).
🧩 Apache Modules
Modules are plug-ins that extend the core capabilities of Apache.
Some popular modules include:
mod_ssl: Enables HTTPS (SSL/TLS support)
mod_rewrite: URL rewriting
mod_auth: User authentication
mod_cache: Content caching
mod_proxy: Proxy and load balancing support
Admins can enable/disable these based on their needs.
Sure! Here's a neatly rearranged and expanded version of your Linux file processing and mathematical commands notes,
tailored for your exam preparation:
🧮 Mathematical Commands
1. expr – Evaluate Integer Expressions
Purpose: Perform arithmetic operations (integers only).
Syntax:
expr operand1 operator operand2
Operators:
Symbol Operation
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo
Note: Use \* for multiplication to avoid shell interpretation.
Examples:
expr 10 + 5 # Output: 15
expr 20 / 4 # Output: 5
expr 10 \* 3 # Output: 30
2. bc – Basic Calculator
Purpose: Performs calculations with integers and floating-point numbers.
To Use:
bc
Float Division:
scale=2
10/3 # Output: 3.33
Example:
echo "scale=2; 22/7" | bc # Output: 3.14
🔹 Key Features:
Pipes are unidirectional (data flows left to right).
Pipes allow multiple commands to work together in a chain.
Pipes help in reducing intermediate files by sending output directly between commands.
Pipes work in main memory (RAM), not on disk.
✅
🔹 tee Command (Pipe + Save to File)
Definition:
The tee command reads from standard input, then:
Displays the data (to stdout), and
🔹
Writes the data into one or more files.
Syntax:
command1 | tee filename
🔹
Use tee when you want to save and view output at the same time.
Example:
ls -l | tee output.txt
🔹
Displays the result of ls -l on the screen and saves it in output.txt.
Example with Append:
ls -l | tee -a output.txt
Appends output to an existing file.
✅ Conclusion:
Pipes connect commands for efficient, real-time data processing.
They help eliminate temporary files and speed up scripting tasks.
Combined with commands like grep, sort, uniq, and tee, pipes make Linux a powerful tool for automation and processing.
🧠
🔹 Pattern Filtering with Regular Expressions
8. grep – Global Regular Expression Print
Purpose: Searches files for lines that match a pattern.
Syntax: grep [options] "pattern" <filename>
Options:
-i → Ignore case.
-v → Invert match.
-c → Count of matched lines.
-n → Show line numbers.
-w → Match whole word.
Example:
grep -w "Linux" file.txt → Matches "Linux" as a whole word.