UNIT 4 Introduction to Linux & shell programming
UNIT 4 Introduction to Linux & shell programming
a. Origins:
Open Source: Released under the GNU General Public License (GPL).
Distributions: Various distributions (distros) evolved, each tailored to specific needs (e.g.,
Ubuntu, Fedora, Debian).
c. Significance:
Widespread Adoption: Used in diverse applications, from servers and embedded systems to
desktops and mobile devices.
2. Architecture of LINUX:
a. Monolithic Kernel:
b. Key Components:
Device Drivers: Facilitate communication between hardware devices and the kernel.
3. Features of LINUX:
User Permissions: Implements a robust permission system for file access and system
operations.
Firewalls and Encryption: Offers tools for securing networks and data.
Known for high stability and reliability, often used in critical systems.
e. Portability:
f. Networking Capabilities:
4. Introduction to vi Editor:
a. Vi vs. Vim:
b. Modes:
c. Basic Commands:
Navigation: h, j, k, l.
d. Advanced Features:
e. Customization:
a. Basic Commands:
c. System Information:
d. Process Management:
e. Package Management:
1. Linux Session:
a. Definition:
Shell: A shell is a command-line interpreter that provides a user interface to interact with
the operating system. It interprets user commands and executes them.
b. Types of Shells:
Non-login (Interactive) Session: Accessed without the need for a login process.
2. Standard Streams:
a. Overview:
b. Redirection:
c. Examples:
3. Pipes:
a. Definition:
Pipe (|): Connects the output of one command to the input of another, allowing for the
chaining of commands.
b. Example:
4. Tee Command:
a. Definition:
tee: Reads from stdin and writes to both stdout and files.
b. Example:
a. Background Execution:
&: Executes a command in the background, allowing the shell to continue to accept
commands.
b. Example:
. Command-Line Editing:
b. History Navigation:
7. Quotes:
c. Example:
echo 'Single quotes preserve $variable' # Output: Single quotes preserve $variable
echo "Double quotes allow $variable" # Output: Double quotes allow the value of variable
8. Command Substitution:
a. Syntax:
b. Example:
9. Job Control:
a. Overview:
b. Example:
10. Aliases:
a. Definition:
b. Example:
11. Variables:
a. User-Defined Variables:
Assignment: variable_name=value
b. Predefined Variables:
c. Example:
username="John"
12. Options:
a. Overview:
b. Example:
Filters:
a. Definition:
Filter: A program that processes an input stream and produces an output stream.
b. Examples:
2. Concatenating Files:
a. cat Command:
b. Example:
b. Example:
b. Example:
cut -d':' -f1,3 file.txt # Display fields 1 and 3 using ':' as the delimiter
5. Sorting:
a. sort Command:
b. Example:
1. Linux Session:
a. Definition:
Shell: A shell is a command-line interpreter that provides a user interface to interact with
the operating system. It interprets user commands and executes them.
b. Types of Shells:
Non-login (Interactive) Session: Accessed without the need for a login process.
2. Standard Streams:
a. Overview:
b. Redirection:
c. Examples:
bashCopy code
command > output.txt # Redirect stdout to a file command < input.txt # Redirect stdin from a file
command 2> error.log # Redirect stderr to a file
3. Pipes:
a. Definition:
Pipe (|): Connects the output of one command to the input of another, allowing for the
chaining of commands.
b. Example:
bashCopy code
4. Tee Command:
a. Definition:
tee: Reads from stdin and writes to both stdout and files.
b. Example:
bashCopy code
5. Command Execution:
a. Background Execution:
&: Executes a command in the background, allowing the shell to continue to accept
commands.
b. Example:
bashCopy code
6. Command-Line Editing:
b. History Navigation:
7. Quotes:
c. Example:
bashCopy code
echo 'Single quotes preserve $variable' # Output: Single quotes preserve $variable echo "Double
quotes allow $variable" # Output: Double quotes allow the value of variable
8. Command Substitution:
a. Syntax:
`command`: Executes the command and substitutes its output.
b. Example:
bashCopy code
9. Job Control:
a. Overview:
b. Example:
bashCopy code
emacs & # Start emacs in the background jobs # List background jobs fg 1 # Bring the first job to the
foreground
10. Aliases:
a. Definition:
b. Example:
bashCopy code
11. Variables:
a. User-Defined Variables:
Assignment: variable_name=value
b. Predefined Variables:
c. Example:
bashCopy code
a. Overview:
b. Example:
bashCopy code
a. Configuration Files:
b. Customizing Prompt:
c. Example:
bashCopy code
PS1='\u@\h:\w\$ ' # Customizes the shell prompt to display user, host, and current directory
Filters:
a. Definition:
Filter: A program that processes an input stream and produces an output stream.
b. Examples:
bashCopy code
2. Concatenating Files:
a. cat Command:
cat: Concatenates and displays the content of files.
b. Example:
bashCopy code
b. Example:
bashCopy code
head -n 10 file.txt # Display the first 10 lines of file.txt tail -n 20 file.txt # Display the last 20 lines of
file.txt
b. Example:
bashCopy code
cut -d':' -f1,3 file.txt # Display fields 1 and 3 using ':' as the delimiter paste file1.txt file2.txt >
merged.txt
5. Sorting:
a. sort Command:
b. Example:
bashCopy code
6. Translating Characters:
a. tr Command:
tr: Translates or deletes characters.
b. Example:
a. uniq Command:
b. Example:
a. wc Command:
b. Example:
9. Comparing Files:
a. diff Command:
b. Example: