The Ultimate Guide to Linux and Shell Scripting: BEGINNER FRIENDLY

Badal RajBadal Raj
4 min read

Table of Contents

  1. Introduction to Linux

  2. Linux File System Hierarchy

  3. Basic Linux Commands

  4. File Permissions and Ownership

  5. Text Processing Commands

  6. Process Management

  7. Introduction to Shell Scripting

  8. Variables and Input

  9. Conditional Statements

  10. Loops

  11. 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)

DistroBest For
UbuntuBeginners
DebianStability
CentOSServers
Arch LinuxAdvanced Users
Kali LinuxCybersecurity

2. Linux File System Hierarchy

Linux follows a standard directory structure:

DirectoryPurpose
/Root directory
/binEssential binaries (ls, cp)
/etcConfiguration files
/homeUser directories
/varVariable data (logs)
/tmpTemporary files
/usrUser programs

Example:

ls /  # List root directory

3. Basic Linux Commands

Navigation

CommandDescriptionExample
pwdPrint current directorypwd
cdChange directorycd /home/user
lsList filesls -l

File Operations

CommandDescriptionExample
touchCreate filetouch file.txt
cpCopy filecp file.txt backup/
mvMove/renamemv file.txt newname.txt
rmDelete filerm 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

CommandDescriptionExample
grepSearch textgrep "error" log.txt
sedFind & replacesed 's/old/new/g' file.txt
awkText processingawk '{print $1}' file.txt
sortSort linessort file.txt
uniqRemove duplicatesuniq file.txt

6. Process Management

CommandDescriptionExample
psList processesps aux
topLive process monitortop
killTerminate processkill -9 PID
bg / fgBackground/Foreground jobsbg %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"
0
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!