Module 3 - Scripting and Tools
Course: Introduction to Problem Solving (ESC101)
Target Audience: 1st Year CSE Students
Introduction to the Shell and Scripting
What is a Shell?
A Shell is a special program that acts as a bridge between the user and the computer's
Operating System (the Kernel). It takes your typed commands and translates them so the
computer can understand what to do.
What is a Shell Script?
A shell script is a simple text file containing a list of commands. Instead of typing commands
one by one, you put them in a script and run it. This is used to automate repetitive tasks like
taking backups or cleaning up old files.
I. File System and Directory Management
1. ls (List)
Displays a list of files and folders in your current location.
● Example: ls -l
● Explanation: The -l option provides a "long listing" showing details like file size, owner,
and the date it was created.
2. mkdir (Make Directory)
Creates a new empty folder.
● Example: mkdir MyAssignments
● Explanation: This command creates a folder named "MyAssignments" in your current
directory.
3. touch
Creates a new, empty file or updates the timestamp of an existing file.
● Example: touch lab1.c
● Explanation: If "lab1.c" doesn't exist, it creates it. If it does exist, it just updates the last
modified time.
4. cp (Copy)
Makes a duplicate of a file or folder.
● Example: cp [Link] backup_notes.txt
● Explanation: This takes the content of "[Link]" and puts it into a new file called
"backup_notes.txt".
5. mv (Move / Rename)
Moves a file to a different folder or changes its name.
● Example: mv [Link] new_name.txt
● Explanation: This effectively renames the file. If you provide a folder path like mv [Link]
documents/, it moves the file.
6. rm (Remove)
Deletes files or folders. Use with caution!
● Example: rm old_file.txt
● Explanation: To delete a folder and everything inside it, use rm -r folder_name.
7. rmdir (Remove Directory)
Deletes a folder, but only if it is completely empty.
● Example: rmdir empty_folder
● Explanation: If there are files inside, this command will show an error. Use rm -r for non-
empty folders.
8. find
Searches for files and directories based on their name, size, or type.
● Example: find . -name "*.pdf"
● Explanation: This looks in the current folder (.) for any file ending in .pdf.
9. tree
Displays the directory structure in a visual, branch-like format.
● Example: tree
● Explanation: It helps you see which folders are inside other folders at a glance.
II. File Viewing and Counting
10. cat (Concatenate)
Displays the entire content of a file on the screen.
● Example: cat [Link]
● Explanation: Good for short files. For long files, it scrolls past too fast.
11. less
Opens a file in a way that lets you scroll up and down.
● Example: less large_file.log
● Explanation: Press the arrow keys to move and q to exit.
12. head
Shows the first few lines of a file (default is 10).
● Example: head -n 5 [Link]
● Explanation: This displays only the first 5 lines of "[Link]".
13. tail
Shows the last few lines of a file.
● Example: tail -f [Link]
● Explanation: The -f (follow) option is very famous; it keeps the file open and shows new
lines as they are added in real-time.
14. wc (Word Count)
Counts lines, words, and characters in a file.
● Example: wc -l [Link]
● Explanation: The -l flag tells you exactly how many lines are in the file.
III. Text Manipulation and Processing
15. sort
Arranges lines of text in alphabetical or numerical order.
● Example: sort [Link]
● Explanation: It does not change the original file; it just shows the sorted version on your
screen.
16. uniq (Unique)
Removes duplicate lines that are next to each other.
● Example: sort [Link] | uniq
● Explanation: We usually "sort" the file first so that identical lines are adjacent, then use
"uniq" to delete the repeats.
17. cut
Extracts specific parts (columns) from each line of a file.
● Example: cut -d',' -f1 student_data.csv
● Explanation: This uses a comma as a separator (-d',') and picks the first column (-f1).
18. tr (Translate)
Replaces or deletes specific characters.
● Example: cat [Link] | tr 'a-z' 'A-Z'
● Explanation: This converts all lowercase letters in the file to uppercase.
19. paste
Merges lines from multiple files side-by-side.
● Example: paste [Link] [Link]
● Explanation: It puts the first line of [Link] next to the first line of [Link].
20. diff (Difference)
Compares two files and shows the lines that are different.
● Example: diff version1.c version2.c
● Explanation: Very helpful for programmers to see what changed in their code.
IV. Searching and Advanced Text Editing
21. grep (Global Regular Expression Print)
Searches for a specific word or pattern inside files.
● Example: grep "error" [Link]
● Explanation: It prints every line that contains the word "error".
22. egrep (Extended Grep)
A version of grep that allows more complex search patterns.
● Example: egrep "apple|orange" [Link]
● Explanation: The | means "OR". This finds lines with either apple or orange.
23. fgrep (Fixed Grep)
A faster version of grep that looks for exact strings and ignores special characters.
● Example: fgrep "[Link]" [Link]
● Explanation: Use this when you are searching for simple text that doesn't need complex
patterns.
24. awk
A powerful language for processing files arranged in columns.
● Example: awk '{print $1, $3}' [Link]
● Explanation: This prints the 1st and 3rd columns of every line in the file.
25. sed (Stream Editor)
Used for finding and replacing text in a file automatically.
● Example: sed 's/day/night/g' [Link]
● Explanation: The s stands for substitute. It changes every "day" to "night" in "[Link]".
26. xargs
Takes the output of one command and passes it as an argument to another command.
● Example: find . -name "*.tmp" | xargs rm
● Explanation: It finds all .tmp files and then passes that list to the rm command to delete
them all at once.
V. Permissions and System Monitoring
27. chmod (Change Mode)
Changes who can Read, Write, or Execute a file.
● Example: chmod +x [Link]
● Explanation: This makes the file "executable," meaning you can now run it like a
program.
28. chown (Change Owner)
Changes which user or group owns a file.
● Example: sudo chown admin:admin [Link]
● Explanation: Requires administrator (sudo) rights. It changes the owner of the file to
"admin".
29. ps (Process Status)
Shows a snapshot of the programs currently running on the computer.
● Example: ps aux
● Explanation: Shows every process running on the system, who started it, and how much
memory it uses.
30. top
Displays a live, real-time list of running processes.
● Example: top
● Explanation: Like a "Task Manager" that updates every few seconds. Press q to stop
viewing.
31. kill
Stops a running program.
● Example: kill 1234
● Explanation: You need the "Process ID" (PID) to tell the computer which specific
program to stop.
32. du (Disk Usage)
Shows how much space a file or folder is taking up.
● Example: du -sh my_folder
● Explanation: -s gives a summary, and -h makes it "human-readable" (showing MB or GB
instead of bytes).
33. df (Disk Free)
Shows how much total space is left on your hard drive.
● Example: df -h
● Explanation: It lists all "file systems" and tells you how much percentage is used.
34. free
Shows the amount of used and free RAM (Memory).
● Example: free -h
● Explanation: Helps you see if your computer is running out of memory because too
many apps are open.
35. man (Manual)
The "Help" command. Shows the manual for any other command.
● Example: man grep
● Explanation: If you forget what grep does, type this to see all its options and
instructions.
VI. Networking and Remote Access
36. ping
Checks if a computer or website is reachable on the network.
● Example: ping [Link]
● Explanation: It sends a small "packet" and waits for it to bounce back. It also tells you
the speed (latency).
37. curl
Transfers data from or to a server. Used often to download data from a web link.
● Example: curl [Link]
● Explanation: It will download and show the HTML code of that website on your screen.
38. wget
A simple tool to download files from the internet.
● Example: wget [Link]
● Explanation: It downloads the file directly into your current folder.
39. ssh (Secure Shell)
Allows you to log into and control another computer remotely.
● Example: ssh username@[Link]
● Explanation: Everything you type goes to the other computer, and you see its output on
your screen.
40. scp (Secure Copy)
Securely copies files between two computers over a network.
● Example: scp my_file.txt user@remote:/home/user/
● Explanation: Like the cp command, but it works across different computers.
41. rsync (Remote Sync)
A smart tool for copying and backing up files.
● Example: rsync -av local_folder/ remote_folder/
● Explanation: It is faster than scp because it only copies the files that have changed.
VII. Scripting: Conditions and Loops
42. Conditions (if-elif-else)
Used to make decisions in a script.
Example:
if [ $marks -ge 40 ]; then
echo "Pass"
else
echo "Fail"
fi
Explanation: If the condition in the brackets is true, the first part runs. Otherwise, the "else"
part runs.
43. Loop Statements (for, while)
Used to repeat a task many times.
● For Loop: Used when you know how many times to repeat.
○ Example: for i in 1 2 3; do echo $i; done
● While Loop: Repeats as long as a condition is true.
○ Example:
count=1
while [ $count -le 3 ]; do
echo $count
count=$((count + 1))
done
VIII. Advanced Tools
44. Latex
A document writing system. You don't "style" text with buttons; you write code to define
structure. Unlike Word, where you click 'Bold', in LaTeX you type a command.
● Explanation: It is used by scientists and engineers to write papers with complex math
formulas. It makes documents look very professional.
● Online Editor: The most popular way to use LaTeX without installing anything is
Overleaf: [Link]
LaTeX Example Code:
\documentclass{article}
\usepackage{amsmath}
\title{My First CSE Report}
\author{First Year Student}
\date{December 2025}
\begin{document}
\maketitle
\section{Introduction}
This is a paragraph written in LaTeX. It allows us to write complex math equations easily.
\section{Mathematics Example}
Here is a famous formula:
\begin{equation}
E = mc^2
\end{equation}
We can also write fractions like $\frac{1}{2}$ and square roots like $\sqrt{16}$.
\end{document}
Expected Output:
When you run this code, it creates a professionally typeset PDF.
1. It creates a center-aligned title with the name and date.
2. It creates numbered sections (1. Introduction, 2. Mathematics Example).
3. The formula E=mc² is centered and given a number (1).
4. Symbols like fractions and roots are rendered perfectly.
45. Github
A website where programmers store their code and work together.
● Explanation: It uses a system called "Git" to keep track of every change made to a
project. If you make a mistake, you can "go back in time" to a previous version.
GitHub Practical Tutorial: Uploading a Project
Prerequisites
Before proceeding, ensure you have:
● Git installed — check with: git --version
● A GitHub repository already created (for example, [Link]
[Link]).
● Git configured:
git config --global [Link] "Your Name"
git config --global [Link] "[Link]@[Link]"
Step 1: Create a local project folder
cd ~ # Go to home directory
mkdir git-demo # Create a new folder
cd git-demo # Move into the folder
Step 2: Initialize a Git repository
git init
This command creates a hidden folder .git which stores version history and configuration.
Step 3: Create a simple file
Let's create a text file with some content:
echo "This is my first file uploaded to GitHub!" > [Link]
Verify it exists:
cat [Link]
Step 4: Stage and commit the file
Tell Git to track and save the file as a snapshot:
git add [Link]
git commit -m "Add [Link] with sample content"
git add stages changes, and git commit saves them to the repository.
Step 5: Connect to GitHub repository
Link your local folder to your GitHub repository. Replace the URL with your actual repo URL.
# For HTTPS:
git remote add origin [[Link]
[Link]]([Link]
# Verify it is connected:
git remote -v
Step 6: Push (upload) the file to GitHub
git branch -M main # Rename default branch to main
git push -u origin main # Upload the commit to GitHub
Step 7: Confirm upload
Go to your GitHub repository page. You should now see the [Link] file and your commit
message.
Step 8: Update the file
echo "Added another line to the file." >> [Link]
git status
git diff
git add [Link]
git commit -m "Update [Link] with another line"
git push
Refresh the GitHub page to see the new version.
Summary of Commands
mkdir git-demo
cd git-demo
git init
echo "Text" > [Link]
git add [Link]
git commit -m "Message"
git remote add origin [URL]
git branch -M main
git push -u origin main
46. Makefile
A file that automates the process of building (compiling) a software project.
● Explanation: Instead of typing long commands to compile 100 files, you just type make.
It is smart enough to only re-compile files you recently edited.
47. Open Source Projects
Software projects where the source code is public for anyone to see and fix.
● Explanation: Examples include Linux, Android, and Python. People from all over the
world collaborate to make the software better for everyone.