DEV Community

King coder
King coder

Posted on

LINUX & SHELL PROGRAMMING β€” COMPLETE NOTES (BCA-2 CIITM Dhanbad)

🟦 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
Enter fullscreen mode Exit fullscreen mode

⭐ 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
Enter fullscreen mode Exit fullscreen mode

⭐ 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
Enter fullscreen mode Exit fullscreen mode

🟦 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
Enter fullscreen mode Exit fullscreen mode

Lower value β†’ higher priority
Higher value β†’ lower priority


⭐ 3. Scheduling Processes

Using cron

Used for repeated jobs.

crontab -e
Enter fullscreen mode Exit fullscreen mode

Cron format:

min hour day month weekday command
Enter fullscreen mode Exit fullscreen mode

Using at

One-time scheduling:

at 17:00
Enter fullscreen mode Exit fullscreen mode

⭐ 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
Enter fullscreen mode Exit fullscreen mode

🟦 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

  1. Create file:
nano script.sh
Enter fullscreen mode Exit fullscreen mode
  1. Add shebang:
#!/bin/bash
echo "Hello World"
Enter fullscreen mode Exit fullscreen mode
  1. Make executable:
chmod +x script.sh
Enter fullscreen mode Exit fullscreen mode
  1. Run:
./script.sh
Enter fullscreen mode Exit fullscreen mode

⭐ Shell Variables

name="Abhishek"
echo "My name is $name"
Enter fullscreen mode Exit fullscreen mode

Variable rules:

  • No spaces
  • Use $var to access
  • Strings need quotes

System variables: $HOME, $USER, $PATH


⭐ Input Using read

read username
echo "You typed $username"
Enter fullscreen mode Exit fullscreen mode

⭐ Conditional Statements

if [ $a -gt 10 ]
then
  echo "Greater"
else
  echo "Smaller"
fi
Enter fullscreen mode Exit fullscreen mode

Operators:

  • -eq, -ne, -gt, -lt, -ge, -le

⭐ Case Statement

case $choice in
1) echo "One" ;;
2) echo "Two" ;;
*) echo "Invalid" ;;
esac
Enter fullscreen mode Exit fullscreen mode

⭐ Looping

For loop

for i in 1 2 3
do
 echo $i
done
Enter fullscreen mode Exit fullscreen mode

While loop

while [ $i -lt 5 ]
do
 echo $i
 i=$((i+1))
done
Enter fullscreen mode Exit fullscreen mode

⭐ Passing Arguments

./script.sh arg1 arg2
echo "First arg = $1"
echo "Second arg = $2"
Enter fullscreen mode Exit fullscreen mode

⭐ Arrays

fruits=("apple" "banana" "cherry")
echo ${fruits[1]}
echo ${fruits[@]}
Enter fullscreen mode Exit fullscreen mode

⭐ Functions

hello() {
  echo "Hello $1"
}
hello "Abhishek"
Enter fullscreen mode Exit fullscreen mode

⭐ 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
Enter fullscreen mode Exit fullscreen mode

🟦 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
Enter fullscreen mode Exit fullscreen mode

⭐ egrep (extended grep)

Supports advanced patterns:

egrep "cat|dog" file.txt
Enter fullscreen mode Exit fullscreen mode

⭐ sed (find & replace)

sed 's/old/new/g' file.txt
Enter fullscreen mode Exit fullscreen mode

⭐ awk (pattern scanning)

awk '{print $1}' file.txt
Enter fullscreen mode Exit fullscreen mode

Top comments (0)