Introduction to Linux:
1. A Brief History of LINUX:
a. Origins:
Creator: Linux was created by Linus Torvalds in 1991.
Inspiration: Developed as a Unix-like operating system kernel.
Open Source: Released under the GNU General Public License (GPL).
b. Growth and Development:
Community Involvement: Rapid development through collaboration with a global
community of developers.
Distributions: Various distributions (distros) evolved, each tailored to specific needs (e.g.,
Ubuntu, Fedora, Debian).
c. Significance:
Open Source Philosophy: Linux embodies the open-source philosophy, fostering
collaboration, transparency, and community-driven development.
Widespread Adoption: Used in diverse applications, from servers and embedded systems to
desktops and mobile devices.
2. Architecture of LINUX:
a. Monolithic Kernel:
Linux follows a monolithic kernel architecture.
Kernel: Manages system resources and provides essential services.
b. Key Components:
Process Management: Handles the creation, scheduling, and termination of processes.
Memory Management: Manages system memory and allocates resources to processes.
File System: Provides file and directory management functionalities.
Device Drivers: Facilitate communication between hardware devices and the kernel.
c. User Space and Kernel Space:
User Space: Where user applications and processes run.
Kernel Space: Reserved for the operating system's core functions.
3. Features of LINUX:
a. Multiuser and Multitasking:
Supports multiple users and concurrent execution of processes.
b. Security:
User Permissions: Implements a robust permission system for file access and system
operations.
Firewalls and Encryption: Offers tools for securing networks and data.
c. Stability and Reliability:
Known for high stability and reliability, often used in critical systems.
d. Open Source Philosophy:
Code accessibility and modifiability foster innovation and collaboration.
e. Portability:
Runs on a variety of hardware architectures, making it versatile.
f. Networking Capabilities:
Inherent support for networking protocols and services.
g. Command-Line Interface (CLI) and Graphical User Interface (GUI):
Offers both CLI and GUI interfaces for user interaction.
4. Introduction to vi Editor:
a. Vi vs. Vim:
Vi (Visual Editor): Original version.
Vim (Vi Improved): Enhanced version with additional features.
b. Modes:
Command Mode: For navigation and issuing commands.
Insert Mode: For text input.
Visual Mode: For selecting text.
c. Basic Commands:
Navigation: h, j, k, l.
Saving and Quitting: :w, :q, :wq.
d. Advanced Features:
Search and Replace: /pattern, :%s/old/new/g.
Copy and Paste: y, p.
e. Customization:
Configuration Files: ~/.vimrc for custom settings.
5. Linux Commands:
a. Basic Commands:
ls: List files and directories.
pwd: Print the current working directory.
cd: Change directory.
cp: Copy files or directories.
mv: Move or rename files or directories.
rm: Remove files or directories.
b. File and Text Manipulation:
cat: Concatenate and display file contents.
grep: Search for patterns in files.
echo: Display messages.
c. System Information:
uname: Display system information.
df: Display disk space usage.
free: Display free and used memory.
d. Process Management:
ps: Display information about active processes.
kill: Terminate processes.
e. Package Management:
apt: Advanced Package Tool (used in Debian-based distributions).
yum: Yellowdog Updater, Modified (used in Red Hat-based distributions).
Introduction to Shells: Linux Session
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:
Bash (Bourne Again Shell): Common default shell for Linux.
Zsh (Z Shell), Fish: Other popular shells with extended features.
c. Starting a Linux Session:
Login: Provides access to the system using a username and password.
Non-login (Interactive) Session: Accessed without the need for a login process.
2. Standard Streams:
a. Overview:
Standard Input (stdin): Represents input from the keyboard.
Standard Output (stdout): Represents output to the screen.
Standard Error (stderr): Represents error messages.
b. Redirection:
>: Redirects stdout to a file.
<: Redirects stdin from a file.
2>: Redirects stderr to a file.
c. Examples:
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:
command1 | command2 # Output of command1 is the input of command2
4. Tee Command:
a. Definition:
tee: Reads from stdin and writes to both stdout and files.
b. Example:
command | tee output.txt # Output of command is displayed and written to output.txt
5. Command Execution:
a. Background Execution:
&: Executes a command in the background, allowing the shell to continue to accept
commands.
b. Example:
command & # Execute command in the background
. Command-Line Editing:
a. Line Editing Commands:
Ctrl + A: Move to the beginning of the line.
Ctrl + E: Move to the end of the line.
Ctrl + U: Delete from the cursor to the beginning of the line.
b. History Navigation:
Ctrl + R: Search backward through command history.
7. Quotes:
a. Single Quotes ('):
Preserve the literal value of each character within the quotes.
b. Double Quotes ("):
Allow for variable substitution and interpretation of certain special characters.
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:
`command`: Executes the command and substitutes its output.
b. Example:
current_directory=`pwd` # Assigns the current directory to the variable
9. Job Control:
a. Overview:
jobs: Lists the current jobs.
bg: Puts a job in the background.
fg: Brings a job to the foreground.
b. Example:
emacs & # Start emacs in the background
jobs # List background jobs
fg 1 # Bring the first job to the foreground
10. Aliases:
a. Definition:
alias: Creates a shortcut or alias for a command.
b. Example:
alias ll='ls -alF' # Create an alias 'll' for 'ls -alF'
11. Variables:
a. User-Defined Variables:
Assignment: variable_name=value
b. Predefined Variables:
$HOME: User's home directory.
$PATH: List of directories to search for executable files.
c. Example:
username="John"
echo "Hello, $username!"
12. Options:
a. Overview:
set: Displays shell options.
set -o option: Enables a shell option.
set +o option: Disables a shell option.
b. Example:
set -o noclobber # Prevent overwriting files with '>'
Filters:
1. Filters and Pipes:
a. Definition:
Filter: A program that processes an input stream and produces an output stream.
b. Examples:
cat file.txt | grep "pattern" | sort
2. Concatenating Files:
a. cat Command:
cat: Concatenates and displays the content of files.
b. Example:
cat file1.txt file2.txt > combined.txt
3. Display Beginning and End of Files:
a. head and tail Commands:
head: Displays the beginning of a file.
tail: Displays the end of a file.
b. Example:
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
4. Cut and Paste:
a. cut and paste Commands:
cut: Removes sections from each line of a file.
paste: Merges lines from multiple files.
b. Example:
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:
sort: Sorts lines of text files.
b. Example:
sort file.txt > sorted.txt
Introduction to Shells: Linux Session
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:
Bash (Bourne Again Shell): Common default shell for Linux.
Zsh (Z Shell), Fish: Other popular shells with extended features.
c. Starting a Linux Session:
Login: Provides access to the system using a username and password.
Non-login (Interactive) Session: Accessed without the need for a login process.
2. Standard Streams:
a. Overview:
Standard Input (stdin): Represents input from the keyboard.
Standard Output (stdout): Represents output to the screen.
Standard Error (stderr): Represents error messages.
b. Redirection:
>: Redirects stdout to a file.
<: Redirects stdin from a file.
2>: Redirects stderr to a file.
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
command1 | command2 # Output of command1 is the input of command2
4. Tee Command:
a. Definition:
tee: Reads from stdin and writes to both stdout and files.
b. Example:
bashCopy code
command | tee output.txt # Output of command is displayed and written to output.txt
5. Command Execution:
a. Background Execution:
&: Executes a command in the background, allowing the shell to continue to accept
commands.
b. Example:
bashCopy code
command & # Execute command in the background
6. Command-Line Editing:
a. Line Editing Commands:
Ctrl + A: Move to the beginning of the line.
Ctrl + E: Move to the end of the line.
Ctrl + U: Delete from the cursor to the beginning of the line.
b. History Navigation:
Ctrl + R: Search backward through command history.
7. Quotes:
a. Single Quotes ('):
Preserve the literal value of each character within the quotes.
b. Double Quotes ("):
Allow for variable substitution and interpretation of certain special characters.
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
current_directory=`pwd` # Assigns the current directory to the variable
9. Job Control:
a. Overview:
jobs: Lists the current jobs.
bg: Puts a job in the background.
fg: Brings a job to the foreground.
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:
alias: Creates a shortcut or alias for a command.
b. Example:
bashCopy code
alias ll='ls -alF' # Create an alias 'll' for 'ls -alF'
11. Variables:
a. User-Defined Variables:
Assignment: variable_name=value
b. Predefined Variables:
$HOME: User's home directory.
$PATH: List of directories to search for executable files.
c. Example:
bashCopy code
username="John" echo "Hello, $username!"
12. Options:
a. Overview:
set: Displays shell options.
set -o option: Enables a shell option.
set +o option: Disables a shell option.
b. Example:
bashCopy code
set -o noclobber # Prevent overwriting files with '>'
13. Shell/Environment Customization:
a. Configuration Files:
~/.bashrc: Per-user shell customization file.
/etc/bashrc: System-wide shell configuration file.
b. Customizing Prompt:
PS1: Primary prompt string variable.
PS2: Secondary prompt string variable.
c. Example:
bashCopy code
PS1='\u@\h:\w\$ ' # Customizes the shell prompt to display user, host, and current directory
Filters:
1. Filters and Pipes:
a. Definition:
Filter: A program that processes an input stream and produces an output stream.
b. Examples:
bashCopy code
cat file.txt | grep "pattern" | sort
2. Concatenating Files:
a. cat Command:
cat: Concatenates and displays the content of files.
b. Example:
bashCopy code
cat file1.txt file2.txt > combined.txt
3. Display Beginning and End of Files:
a. head and tail Commands:
head: Displays the beginning of a file.
tail: Displays the end of a file.
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
4. Cut and Paste:
a. cut and paste Commands:
cut: Removes sections from each line of a file.
paste: Merges lines from multiple files.
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:
sort: Sorts lines of text files.
b. Example:
bashCopy code
sort file.txt > sorted.txt
6. Translating Characters:
a. tr Command:
tr: Translates or deletes characters.
b. Example:
tr 'a-z' 'A-Z' < input.txt # Convert lowercase to uppercase
7. Files with Duplicate Lines:
a. uniq Command:
uniq: Removes duplicate lines from a sorted file.
b. Example:
sort file.txt | uniq > unique.txt
8. Count Characters, Words, or Lines:
a. wc Command:
wc: Counts the number of characters, words, and lines in a file.
b. Example:
wc -l file.txt # Count the number of lines in file.txt
9. Comparing Files:
a. diff Command:
diff: Compares files line by line.
b. Example:
diff file1.txt file2.txt