0% found this document useful (0 votes)
4 views9 pages

Lab - Linux and Shell Programming-Assignment 2-Submission

The document explains the structure of the Linux file system, detailing the roles of the boot block, super block, inode block, and data block. It provides examples of basic and advanced file manipulation commands such as mkdir, ls, cp, and rm, along with a shell script for system maintenance and another for command-line argument operations. Additionally, it covers process scheduling in Linux and common networking tools with their usage.

Uploaded by

suraj.199586
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views9 pages

Lab - Linux and Shell Programming-Assignment 2-Submission

The document explains the structure of the Linux file system, detailing the roles of the boot block, super block, inode block, and data block. It provides examples of basic and advanced file manipulation commands such as mkdir, ls, cp, and rm, along with a shell script for system maintenance and another for command-line argument operations. Additionally, it covers process scheduling in Linux and common networking tools with their usage.

Uploaded by

suraj.199586
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

1.

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

Located at the beginning of the disk.


Contains the bootloader (GRUB or LILO) needed to start the operating system.

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

Contains actual file data.


Each file is stored in one or more data blocks.

Creating a Directory Structure and File Manipulation Commands

We can create and manipulate directories and files using basic and advanced commands:

Commands and Examples

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

2. Write a JavaScript program that uses recursion to calculate the factorial


of a given number. Compare the recursive approach with an iterative
approach and explain the differences.

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.

Using cron to Schedule a Task

1. 1 . Open crontab for editing

2. Add a job to execute a script (backup.sh) every day at 2 AM.

3. Save and exit.

4. Verify scheduled tasks:


3. Explore networking tools in Linux by using commands such as ping, nslookup, telnet, arp, netstat, route, ftp, and rlogin.
Provide examples of each command in use and explain their significance in network troubleshooting and management.

Common Networking Commands


Command Usage

ping Check
connectivity to
a remote host.

nslookup Query DNS


records for a
domain.

telnet Connect to a
remote server
on a specified
port.

arp Display or
manipulate the
ARP cache.

netstat Show network


connections
and statistics.
route Display or
modify the
routing table.

ifconfig / ip Show network


interface
details.

rlogin Remote login to


another
machine.
4. Develop a shell script that uses conditional statements and looping constructs to automate a system maintenance task.
The script should check disk usage, clear temporary files, and generate a report. Provide the script and explain each part of
the code

Shell Script to Check Disk Usage, Clear Temp Files, and Generate a Report
Explanation

df /: Gets disk usage.


awk and sed: Extract percentage value.
if condition checks if usage exceeds threshold.
rm -rf /tmp/*: Clears temporary files.
tee -a $LOG_FILE: Logs output.

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() {

echo "Usage: $0 {copy|move|delete} source [destination]"

exit 1

# Check arguments

if [ $# -lt 2 ]; then

usage

fi

ACTION=$1

SOURCE=$2

DEST=$3

case $ACTION in

copy)

cp "$SOURCE" "$DEST"

echo "Copied $SOURCE to $DEST"

;;

move)

mv "$SOURCE" "$DEST"

echo "Moved $SOURCE to $DEST"

;;

delete)

rm -rf "$SOURCE"

echo "Deleted $SOURCE"

;;
*)

usage

esac

You might also like