Linux
Unit 1: Introduction to Linux and Linux Utilities
A Brief History of Linux
• Origin: Linux was created by Linus Torvalds in 1991.
• Open Source: It's an open-source operating system, meaning
its source code is available for anyone to view, modify, and
distribute.
• UNIX-like: Linux is UNIX-like but not UNIX. It was inspired by
the UNIX operating system and designed to be compatible with
it.
Architecture of Linux
• Kernel: The core part of the OS that manages hardware and
system resources.
• Shell: A command interpreter that provides a user interface to
the kernel.
• System Libraries: Provide functions for applications to
interact with the kernel.
• System Utilities: Basic tools and commands for system
management.
Features of Linux
• Multiuser: Multiple users can access the system
simultaneously.
• Multitasking: Allows multiple processes to run concurrently.
• Security: Features like file permissions and user
authentication.
• Portability: Runs on a variety of hardware platforms.
• Stability and Reliability: Known for its robustness and
stability.
Introduction to vi Editor
• vi: A powerful text editor available on almost all UNIX-like
systems.
• Modes:
o Normal Mode: For navigating and manipulating text.
o Insert Mode: For inserting and editing text.
o Command Mode: For executing commands.
Basic Commands:
• i: Enter insert mode.
• Esc: Return to normal mode.
• :w: Save the file.
• :q: Quit vi.
• :wq: Save and quit vi.
Linux Commands
• PATH: Environment variable that specifies the directories
where executable files are located.echo $PATH
• man: Displays the manual pages for commands.man ls
• echo: Prints text to the terminal.echo "Hello, World!"
• printf: Similar to echo but with formatting capabilities.printf
"Name: %s\n" "Linux"
• script: Records a terminal session.script session.log
• passwd: Changes the user password.passwd
• uname: Displays system information.uname -a
• who: Shows who is logged in.who
• date: Displays or sets the system date and time.date
• stty: Changes and prints terminal line settings.stty -a
• pwd: Prints the current working directory.pwd
• cd: Changes the directory.cd /path/to/directory
• mkdir: Creates a new directory.mkdir newdir
• rmdir: Removes an empty directory.rmdir newdir
• ls: Lists files and directories.ls -l
• cp: Copies files or directories.cp source destination
• mv: Moves or renames files or directories.mv oldname
newname
• rm: Removes files or directories.rm file
• cat: Concatenates and displays files.cat file
• more: Displays file content one screen at a time.more file
• wc: Counts lines, words, and characters in a file.wc file
• lp: Sends files to a printer.lp file
• od: Dumps files in octal and other formats.od -c file
• tar: Archives files.tar -cvf archive.tar files
• gzip: Compresses files.gzip file
• File Handling Utilities: Commands like touch, chmod, chown,
etc., for managing files and permissions.
• Security by File Permissions: Use chmod, chown, and chgrp
to manage file and directory permissions and ownership.
Unit 2: Introduction to Shells and Filters
Linux Session
• Login/Logout: Use the login command to start a session and
logout or exit to end it.
Standard Streams
• stdin: Standard input (keyboard by default).
• stdout: Standard output (screen by default).
• stderr: Standard error output (screen by default).
Redirection
• Redirect stdout to a file:command > file
• Append stdout to a file:command >> file
• Redirect stderr to a file:command 2> file
Pipes
• Pass the output of one command as input to
another:command1 | command2
Tee Command
• Reads from stdin and writes to stdout and files:command |
tee file
Command Execution
• Execute a command by typing its name in the terminal.
Command-Line Editing
• Use arrow keys to navigate and edit the command line.
Quotes
• Single Quotes ('): Preserve the literal value of each character.
• Double Quotes ("): Preserve the literal value of most
characters, but allow variable and command substitution.
Command Substitution
• Replace a command with its output:result=$(command)
Job Control
• Manage background and foreground processes.
• &: Run a command in the background.
• jobs: List background jobs.
• fg: Bring a background job to the foreground.
• bg: Resume a background job.
Aliases
• Create shortcuts for commands:alias ll='ls -l'
Variables
• Create and use variables:MYVAR="Hello"
echo $MYVAR
Predefined Variables
• $HOME: User's home directory.
• $PATH: Directories to search for executable files.
• $USER: Current logged-in user.
Options
• Use options to modify the behavior of commands:ls -l
Shell/Environment Customization
• Customize your shell environment using .bashrc
or .bash_profile.
Filters
Filters and Pipes
• Filters: Commands that process input and output.
• Pipes: Connect the output of one command to the input of
another.
Concatenating Files
• Combine multiple files into one:cat file1 file2 >
combined
Display Beginning and End of Files
• head: Display the first few lines.head file
• tail: Display the last few lines.tail file
Cut and Paste
• cut: Extract sections from each line.cut -d ' ' -f 1 file
• paste: Merge lines of files.paste file1 file2
Sorting
• Sort lines in a file:sort file
Translating Characters
• Translate or delete characters:tr 'a-z' 'A-Z'
Files with Duplicate Lines
• uniq: Remove duplicate lines.sort file | uniq
Count Characters, Words, or Lines
• Use wc to count:wc file
Comparing Files
• diff: Compare two files line by line.diff file1 file2
Unit 3: File Structure and Management
Grep: Operation, Grep Family, Searching for File Content
• grep: Searches for patterns in files.grep "pattern" file
Sed: Scripts, Operation, Addresses, Commands, Applications
• sed: Stream editor for modifying files.sed 's/old/new/'
file
UNIX FILE STRUCTURE
• Inode (Index Node): Stores metadata about a file.
• File Descriptors: Unique identifiers for open files.
• System Calls and Device Drivers: Interface for interacting
with hardware.
File Management
• create: creat()
• open: open()
• close: close()
• read: read()
• write: write()
• lseek: lseek()
• link: `