The Ultimate Guide to Linux and Shell Scripting: BEGINNER FRIENDLY


Table of Contents
Introduction to Linux
Linux File System Hierarchy
Basic Linux Commands
File Permissions and Ownership
Text Processing Commands
Process Management
Introduction to Shell Scripting
Variables and Input
Conditional Statements
Loops
Functions
1. Introduction to Linux
What is Linux?
Linux is an open-source, Unix-like operating system kernel first released by Linus Torvalds in 1991. Unlike Windows or macOS, Linux is highly customizable and powers:
Servers (90% of the internet runs on Linux)
Cloud computing (AWS, Google Cloud, Azure)
Embedded systems (Routers, Smart TVs, Android)
Supercomputers (All top 500 supercomputers run Linux)
Why Use Linux?
✔ Free and Open-Source (No licensing fees)
✔ Secure (Less prone to malware)
✔ Lightweight (Runs on old hardware)
✔ Highly Customizable (Choose your own desktop environment)
Popular Linux Distributions
Distro | Best For |
Ubuntu | Beginners |
Debian | Stability |
CentOS | Servers |
Arch Linux | Advanced Users |
Kali Linux | Cybersecurity |
2. Linux File System Hierarchy
Linux follows a standard directory structure:
Directory | Purpose |
/ | Root directory |
/bin | Essential binaries (ls, cp) |
/etc | Configuration files |
/home | User directories |
/var | Variable data (logs) |
/tmp | Temporary files |
/usr | User programs |
Example:
ls / # List root directory
3. Basic Linux Commands
Navigation
Command | Description | Example |
pwd | Print current directory | pwd |
cd | Change directory | cd /home/user |
ls | List files | ls -l |
File Operations
Command | Description | Example |
touch | Create file | touch file.txt |
cp | Copy file | cp file.txt backup/ |
mv | Move/rename | mv file.txt newname.txt |
rm | Delete file | rm file.txt |
Viewing Files
cat file.txt # Display entire file
less file.txt # Scroll through file
head -n 5 file.txt # Show first 5 lines
tail -f log.txt # Follow log in real-time
4. File Permissions and Ownership
Linux uses permissions to control file access:
-rw-r--r-- 1 user group 1024 Jan 1 10:00 file.txt
Permissions:
rw-
(user),r--
(group),r--
(others)Change permissions:
chmod 755 script.sh # rwxr-xr-x
Change ownership:
chown user:group file.txt
5. Text Processing Commands
Command | Description | Example |
grep | Search text | grep "error" log.txt |
sed | Find & replace | sed 's/old/new/g' file.txt |
awk | Text processing | awk '{print $1}' file.txt |
sort | Sort lines | sort file.txt |
uniq | Remove duplicates | uniq file.txt |
6. Process Management
Command | Description | Example |
ps | List processes | ps aux |
top | Live process monitor | top |
kill | Terminate process | kill -9 PID |
bg / fg | Background/Foreground jobs | bg %1 |
7. Introduction to Shell Scripting
A shell script is a program that automates tasks using shell commands.
Create Your First Script
#!/bin/bash
echo "Hello, World!"
Save as
hello.sh
Make executable:
chmod +x hello.sh
Run:
./hello.sh
8. Variables and Input
#!/bin/bash
name="Linux"
echo "Welcome to $name!"
# User input
read -p "Enter your name: " username
echo "Hello, $username!"
9. Conditional Statements
#!/bin/bash
if [ $1 -gt 10 ]; then
echo "Greater than 10"
else
echo "10 or less"
fi
10. Loops
For Loop
for i in {1..5}; do
echo "Number: $i"
done
While Loop
count=1
while [ $count -le 5 ]; do
echo "Count: $count"
((count++))
done
11. Functions
#!/bin/bash
greet() {
echo "Hello, $1!"
}
greet "Alice"
Subscribe to my newsletter
Read articles from Badal Raj directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Badal Raj
Badal Raj
Hi, I'm Badal Raj - a B.Tech CSE student passionate about tech and growth. I'm currently diving into the world of DevOps and building real-world skills step by step. I'll be sharing my journey, learnings, and progress in public so stay tuned!