π¦ UNIT β I : Linux Introduction, Architecture, File System & Basic Commands
β 1. What is Linux?
- Linux is an open-source operating system based on UNIX.
-
It is used in:
- Servers
- Web hosting
- Ethical hacking
- Cloud computing
- Programming environments
- IoT devices
Highly secure, stable, free and powerful.
β 2. Basic Features of Linux
- Multi-user β many users can use at same time
- Multi-tasking β multiple programs run simultaneously
- Open-source β public code, free to edit
- Portable β runs on any hardware
- Secure β permissions + encryption
- Networking β built-in tools for communication
- Shell scripting β automation support
β 3. Linux Flavors (Distributions)
Popular Linux distros:
- Ubuntu
- Debian
- Fedora
- RedHat (RHEL)
- CentOS
- Kali Linux
- Linux Mint
β 4. Advantages of Linux
- Free
- Highly secure
- Virus-free
- Stable and fast
- Customizable
- Used by developers and servers
- Command-line power
β 5. Installation Requirements
- 1β2 GB RAM
- 20β30 GB Disk
- Bootable USB
- 1 GHz Processor
- BIOS/UEFI system
β 6. Linux Architecture
1. Hardware Layer
Physical parts (CPU, RAM, I/O devices)
2. Kernel
- Heart of Linux
- Manages CPU, memory, processes, devices
3. Shell
- Interface between user & kernel
- Executes commands
- Types: Bash, Zsh, Ksh, Tcsh
4. User Space
Applications & utilities
β 7. Linux File System (Standard Directories)
| Directory | Purpose |
|---|---|
/ |
Root of file system |
/home |
User home directories |
/bin |
Basic commands |
/sbin |
System commands |
/etc |
Configuration files |
/usr |
Installed software |
/var |
Logs, mail, spool |
/dev |
Device files |
/tmp |
Temporary files |
/root |
Root userβs home |
β 8. Basic Linux Commands
| Command | Use |
|---|---|
pwd |
Show current directory |
cd |
Change directory |
ls |
List files |
mkdir |
Create directory |
rmdir |
Remove empty directory |
cp |
Copy files/directories |
mv |
Move/rename |
rm |
Delete file/folder |
file |
Show file type |
more, less
|
View long files |
π¦ UNIT β II : File Handling, Shells, Pipes, I/O Redirection, Processes
β 1. Creating & Viewing Files using cat
cat > file.txt # create
cat file.txt # view
cat file1 file2 # view multiple
β 2. File Comparison
| Command | Use |
|---|---|
cmp f1 f2 |
Compare byte-by-byte |
comm f1 f2 |
Compare line-by-line |
β 3. Disk Related Commands
-
df -hβ disk free space -
du -sh folderβ folder size -
mountβ attach device -
umountβ detach device
β 4. Shells in Linux
A shell is a program that reads commands and executes them.
Types:
- Bash
- Sh
- Zsh
- Ksh
- Tcsh
β 5. Processes in Linux
What is a process?
A running program.
Types:
- Foreground
- Background
β 6. Pipes
Used to connect output of one command to another.
ls | wc -l
β 7. I/O Redirection
| Redirection | Meaning |
|---|---|
> |
Output to file |
>> |
Append |
< |
Input from file |
2> |
Error output |
&> |
Redirect both output & error |
β 8. Manual Help Commands
-
man commandβ detailed help -
help commandβ shell built-in help
β 9. Background Processing
command &
jobs
π¦ UNIT β III : Process Management, Scheduling, Commands
β 1. Managing Processes
| Command | Purpose |
|---|---|
ps |
List processes |
top |
Live processes |
kill PID |
Kill process |
jobs |
Background jobs |
bg / fg
|
Move job foreground/background |
β 2. Changing Process Priority (nice & renice)
nice -n 10 program
renice 5 PID
Lower value β higher priority
Higher value β lower priority
β 3. Scheduling Processes
Using cron
Used for repeated jobs.
crontab -e
Cron format:
min hour day month weekday command
Using at
One-time scheduling:
at 17:00
β 4. File Related Commands
-
wc file.txtβ count lines, words, characters -
cut -d',' -f1β cut column -
dd if=in of=outβ copy/convert -
head/tailβ first/last lines
β 5. Math Commands
expr 2 + 3
echo "5*7" | bc
π¦ UNIT β IV : vi/vim Editor & Shell Programming (Detailed)
β 1. vi/vim Editor
Modes:
- Command Mode β navigation
- Insert Mode β i, a, o
-
Last Line Mode β
:w,:q,:wq
Important commands:
| Command | Description |
|---|---|
i |
Insert text |
x |
Delete character |
u |
Undo |
/text |
Search |
:w |
Save |
:q |
Quit |
:wq |
Save & quit |
π¨ SHELL PROGRAMMING (BEST DETAILED NOTES)
β What is Shell Programming?
Shell programming means writing a series of Linux commands in a file to automate tasks.
A shell script is simply a text file with commands.
β Writing Your First Shell Script
- Create file:
nano script.sh
- Add shebang:
#!/bin/bash
echo "Hello World"
- Make executable:
chmod +x script.sh
- Run:
./script.sh
β Shell Variables
name="Abhishek"
echo "My name is $name"
Variable rules:
- No spaces
- Use
$varto access - Strings need quotes
System variables: $HOME, $USER, $PATH
β Input Using read
read username
echo "You typed $username"
β Conditional Statements
if [ $a -gt 10 ]
then
echo "Greater"
else
echo "Smaller"
fi
Operators:
-
-eq,-ne,-gt,-lt,-ge,-le
β Case Statement
case $choice in
1) echo "One" ;;
2) echo "Two" ;;
*) echo "Invalid" ;;
esac
β Looping
For loop
for i in 1 2 3
do
echo $i
done
While loop
while [ $i -lt 5 ]
do
echo $i
i=$((i+1))
done
β Passing Arguments
./script.sh arg1 arg2
echo "First arg = $1"
echo "Second arg = $2"
β Arrays
fruits=("apple" "banana" "cherry")
echo ${fruits[1]}
echo ${fruits[@]}
β Functions
hello() {
echo "Hello $1"
}
hello "Abhishek"
β Automating System Tasks (Example)
- Backup script
- Auto update script
- Log cleanup
- Disk monitoring
- User creation
β FINAL SHELL PROGRAM (BEST EXAM SCRIPT)
#!/bin/bash
# System Backup Script
echo "Enter folder to backup:"
read folder
if [ -d "$folder" ]; then
echo "Backing up..."
tar -czf backup.tar.gz "$folder"
echo "Backup saved as backup.tar.gz"
else
echo "Folder does not exist!"
fi
π¦ UNIT β V : Filters & Regular Expressions
β Simple Filter Commands (Very Important)
| Command | Use |
|---|---|
head |
First 10 lines |
tail |
Last 10 lines |
cut |
Extract columns |
paste |
Merge files |
sort |
Sort text |
uniq |
Remove duplicates |
tr |
Replace characters |
pr |
Format text |
β grep (search text)
grep "hello" file.txt
β egrep (extended grep)
Supports advanced patterns:
egrep "cat|dog" file.txt
β sed (find & replace)
sed 's/old/new/g' file.txt
β awk (pattern scanning)
awk '{print $1}' file.txt
Top comments (0)