Lab - Linux and Shell Programming-Assignment 2-Submission
Lab - Linux and Shell Programming-Assignment 2-Submission
Explain the structure of the Linux file system, including the roles of the boot block, super block, inode block, and data
block. Create a directory structure and demonstrate the use of basic and advanced file commands (such as mkdir, rmdir, ls,
cp, mv, rm) to manipulate the file system. Include examples and screenshots of your commands.
Ans:- The Linux file system is organized into multiple layers and blocks that manage data storage efficiently. The key
components are:
a. Boot Block
b. Super Block
Holds metadata about the file system, including the total number of inodes, blocks, block size, and free space.
Essential for file system integrity.
c. Inode Block
Stores information about files and directories (ownership, permissions, timestamps, file size, etc.).
Each file has a unique inode number.
d. Data Block
We can create and manipulate directories and files using basic and advanced commands:
bash
# Create directories
mkdir -p /home/user/docs/projects
# List directories
ls -l /home/user/docs
# Create files
touch /home/user/docs/file1.txt
# Copy files
cp /home/user/docs/file1.txt /home/user/docs/file2.txt
# Move files
mv /home/user/docs/file2.txt /home/user/docs/backup/
# Remove files
rm /home/user/docs/backup/file2.txt
# Remove directories
rmdir /home/user/docs/backup
Ans:
Process Scheduling in Linux
Linux schedules processes based on priority and time slices using the Completely Fair Scheduler (CFS).
cron, at, and batch allow users to schedule tasks at specific times.
ping Check
connectivity to
a remote host.
telnet Connect to a
remote server
on a specified
port.
arp Display or
manipulate the
ARP cache.
Shell Script to Check Disk Usage, Clear Temp Files, and Generate a Report
Explanation
5. Write a shell script that accepts command-line arguments and performs operations based on the arguments provided.
The script should include options for file manipulation (e.g., copy, move, delete) and display appropriate messages for each
operation. Provide the script and examples of its execution.
Shell Script
#!/bin/bash
# Function to display usage
usage() {
exit 1
# Check arguments
if [ $# -lt 2 ]; then
usage
fi
ACTION=$1
SOURCE=$2
DEST=$3
case $ACTION in
copy)
cp "$SOURCE" "$DEST"
;;
move)
mv "$SOURCE" "$DEST"
;;
delete)
rm -rf "$SOURCE"
;;
*)
usage
esac