0% found this document useful (0 votes)
6 views

OSY Report

Uploaded by

Jay Shimpi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

OSY Report

Uploaded by

Jay Shimpi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

K. K. Wagh Polytechnic, Nashik.

HirabaiHaridasVidyanagari, Amrutdham, Panchavati,Nashik-422003


Department of Computer Technology

Micro-Project Report
Institute Code: 0078
Academic Year: 2023-24 Program: Computer Technology
Course: Operating System (OSY) Course Code: 22516 Scheme: I
Semester: 5 Class: TYCM-Lin Date of Report: / / 2023

Title of Micro-Project: Shell script for File sorting and filtering

1.0 Problem Definition:


Create a shell script that provides users with the ability to organize and view files and directories based on their
sizes and types. The microproject aims to address the need for a more efficient and user-friendly file management
solution in a command-line environment. By developing a shell script, this project intends to automate file
categorization and exploration. To create a tool that allows users to better manage their files by providing options
to categorize them by size and type.

2.0 Rationale:
The rationale behind this project lies in addressing the need for an efficient and user-friendly solution to manage
and explore files in command-line environments. With manual file organization often proving time-consuming and
error-prone, this project aims to simplify and streamline the process. By providing users with the ability to
categorize files by size and type through a well-designed shell script, we intend to automate file management,
ultimately enhancing productivity and file organization for a wide range of users.

3.0 Aim /Benefits of Micro-Project:

● Aim:
The aim of this project is to enhance file management and exploration in a command-line
environment by developing a versatile shell script.

● Objectives:
Develop functions to categorize files and directories by size and type, providing users with
efficient ways to organize their data.

● Benefits:
This shell script simplifies file management in the command line, offering efficient categorization
by size and type, improving productivity, and providing clear data insights for users.

4.0 Course Outcomes Achieved (COs): ( Specify COs which are achieved in micro project e.g. CO502)
CO502.1: Install operating system and configure it.
CO502.2: Use operating system tools to perform various functions.
CO502.6: Apply file management techniques.
5.0 Literature Review:

In the domain of command-line file management, existing systems predominantly involve manual sorting and basic
command-line tools, such as ‘ls,’ ‘find,’ and ‘du.’ While these methods offer versatility, they lack automation and
user-friendly interfaces, making them challenging for non-technical users. The proposed shell script seeks to
address these limitations by providing a user-friendly menu interface and automating file categorization by size and
type, aiming to enhance efficiency and reduce errors in the file management process. This system strikes a balance
between automation and user customization, bridging the gap between existing systems’ strengths and their
limitations, ultimately offering a more efficient and streamlined approach to command-line file management.

6.0 Actual Methodology followed:


The actual methodology for this microproject began with an analysis of current file management practices
in command-line environments to understand user challenges. Using Bash scripting, we designed and
developed a versatile shell script that incorporates functions for categorizing files and directories by :
Size, Type, Created on and Last Modified.
The core of the script automates the file categorization process, utilizing commands like `du`, `stat`,
`cut` for size calculations and file extension parsing for type-based categorization. Testing ensured the
script’s reliability.
This methodology addressed the problem statement by systematically creating a tool that streamlines file
management and exploration, with a strong focus on user satisfaction and efficiency.

7.0 Actual Resources used: (Resources such as Computer/equipment/machine/devices, OS, software, raw material, etc.)
S. No. Name of Resource/material Specifications Qty Remarks

HP Pavilion Laptop, Ryzen 5


1 Laptop 5600H, 8GB RAM installed. 01 For Project Work
512 NVMe SSD
For running
2 Operating System Debian 12, Windows 11 x64 bit 01
Scripts
For scripting ,
3 Software VIM, Microsoft Word 01
documentation
https://www.geeksforgeeks.org/ For Formatting
introduction-linux-shell-shell-scripting/ Output and
4 Websites -
https://www.javatpoint.com/linux- Expected Output
commands layout

8.0 Outputs of the Micro-Project:


Program code:-
#!/bin/bash
path="${1:-.}"
cd "$path" || exit 1

# MENUS SECTION

## MAIN MENU
main-menu(){
clear
while true; do
echo "==== FiDir - File Sort with Filters ===="
echo "1. Sort and display"
echo "2. Filter and display"
echo "3. exit"
echo "========================================"
read -p "Enter your choice: " choice
clear
case $choice in
1) sort-menu
;;
2) filter-menu
;;
3) exit 0
;;
*) echo "Invalid choice, try agin... "
sleep 2
clear
;;
esac
done
}

## SORT MENU
sort-menu(){
clear
while true; do
echo "=================================================="
echo "1. Display files and directories by size"
echo "2. Display files by file type"
echo "3. Sort files/directories by date created"
echo "4. List files/directories by last modified date"
echo "5. Back"
echo "6. Exit"
echo "=================================================="
read -p "Enter your choice: " schoice
clear
case $schoice in
1) display_files_by_size
;;
2) display_files_by_type
;;
3) display_files_by_date_created
;;
4) display_files_by_last_modified
;;
5) main-menu
;;
6) exit 0
;;
*) echo "Invalid choice. Please try again."
;;
esac
done
}

## FILTER MENU
filter-menu(){
clear
while true; do
echo "=================================================="
echo "1. Filter with file type"
echo "2. Filter by permission"
echo "3. Back"
echo "4. exit"
echo "=================================================="
read -p "Enter your choice: " fchoice
clear
case $fchoice in
1) read -p "Enter the file type: " file_type
list_files "$file_type"
;;
2) read -p "Enter permission name (eg. write): " perm
list_files_by_permission $perm
;;
3) main-menu
;;
4) exit 0
;;
*)
echo "Invalid choice. Please select a valid option."
;;
esac
done
}

########################## SORT FUNCTIONS SECTION - START ##########################

# Function to display files and directories by size using du command


display_files_by_size() {
echo "Sort by Size:"
echo "1. Sort from large to small size"
echo "2. Sort from small to large size"
read -p "Enter your choice: " sort_choice

if [ "$sort_choice" = "1" ]; then


sort_option="-k 1,1hr"
elif [ "$sort_choice" = "2" ]; then
sort_option="-k 1h"
else
echo "Invalid choice. Defaulting to big to small size sort."
sort_option="-k 1,1hr"
fi

echo "------------------------ Sort by Size -----------------------"


echo "Size Date (Last Modified) File/Dir Name"
echo "-------------------------------------------------------------"

for file in *; do
if [ -f "$file" ]; then
file_size=$(du -h "$file" | cut -f1)
last_modified_date=$(stat -c "%y" "$file")
printf "%-16s %-20s %s\n" "$file_size" "${last_modified_date%% *}" "$file"
elif [ -d "$file" ]; then
dir_size=$(du -h -s "$file" | cut -f1)
last_modified_date=$(stat -c "%y" "$file")
printf "%-16s %-20s %s\n" "$dir_size" "${last_modified_date%% *}" "$file"
fi
done | sort $sort_option
}

# Function to display files by file type


display_files_by_type() {
local file_types=("jpg|jpeg|png|gif|bmp" "mp4|avi|mkv|mov" "txt" "sh")

for type in "${file_types[@]}"; do


files=($(find $path -maxdepth 1 -type f -name "*.$type"))
if [ ${#files[@]} -gt 0 ]; then
echo "========================= ${type^^} Files ========================="
echo "Size Date (Last Modified) File/Dir Name"
echo "-------------------------------------------------------------"
for file in "${files[@]}"; do
file_date=$(stat -c "%y" "$file")
file_size=$(du -sh "$file" | cut -f1)
echo -e "$file_size\t\t${file_date%% *}\t\t$file"
done
fi
done

# Handle other file types


other_files=($(find $path -maxdepth 1 -type f -not -name "*.*"))
if [ ${#other_files[@]} -gt 0 ]; then
echo "======================== Other Files ========================"
echo "Size Date (Last Modified) File/Dir Name"
echo "-------------------------------------------------------------"
for file in "${other_files[@]}"; do
file_date=$(stat -c "%y" "$file")
file_size=$(du -sh "$file" | cut -f1)
echo -e "$file_size\t${file_date%% *} $file"
done
fi
}

# Function to sort and display files/directories by date created


display_files_by_date_created() {
echo "-------------------- Sort by Date Created -------------------"
echo "Size Date (Created) File/Dir Name"
echo "-------------------------------------------------------------"
for file in *; do
if [ -f "$file" ] || [ -d "$file" ]; then
file_date=$(stat -c "%y" "$file")
file_size=$(du -sh "$file" | cut -f1)
printf "%-16s %-20s %s\n" "$file_size" "${file_date%% *}" "$file"
fi
done | sort -r -k 2
}

# Function to list files/directories by last modified date


display_files_by_last_modified() {
echo "----------------- Sort by Last Modified Date ----------------"
echo "Size Date (Last Modified) File/Dir Name"
echo "-------------------------------------------------------------"
for file in *; do
if [ -f "$file" ] || [ -d "$file" ]; then
last_modified_date=$(stat -c "%y" "$file")
file_size=$(du -sh "$file" | cut -f1)
printf "%-16s %-20s %s\n" "$file_size" "${last_modified_date%% *}" "$file"
fi
done | sort -r -k 2
}

########################### SORT FUNCTIONS SECTION - END ###########################

######################### FILTER FUCNTIONS SECTION - START #########################

# Function to list files of a specific type


list_files() {
local file_type="$1"
local files=($(find $path -maxdepth 1 -type f -name "*.$file_type"))
if [ ${#files[@]} -gt 0 ]; then
echo "======================= $file_type Files ======================="
echo "Size Date (Last Modified) File Name"
echo "-------------------------------------------------------------"
for file in "${files[@]}"; do
file_date=$(stat -c "%y" "$file")
file_size=$(du -sh "$file" | cut -f1)
file_name=$(basename "$file")
echo -e "$file_size\t\t${file_date%% *}\t\t$file_name"
done
else
echo "No $file_type files found in the directory."
fi
}

list_files_by_permission() {
local permission_name="$1"

if [ "$permission_name" == "read" -o "$permission_name" == "r" ]; then


permission_name="readable"
permission="r"
elif [ "$permission_name" == "write" -o "$permission_name" == "w" ]; then
permission="w"
permission_name="writable"
elif [ "$permission_name" == "execute" -o "$permission_name" == "x" ]; then
permission="x"
permission_name="executable"
else
echo "Invalid permission name. Please use 'read', 'write', or 'execute'."
return
fi

local files=($(find $path -maxdepth 1 -type f -name "*"))

if [ ${#files[@]} -gt 0 ]; then


echo "====================== $permission_name files ======================"
echo "Size Date (Last Modified) File Name"
echo "-------------------------------------------------------------"

for file in "${files[@]}"; do


if [ -$permission "$file" ]; then
file_date=$(stat -c "%y" "$file")
file_size=$(du -sh "$file" | cut -f1)
file_name=$(basename $file)
echo -e "$file_size\t\t${file_date%% *}\t\t$file_name"
fi
done
else
echo "No ${permission_name^}able files found in the directory."
fi
}

########################## FILTER FUCNTIONS SECTION - EHD ##########################


main-menu
OUTPUT:-
==== FiDir - File Sort with Filters ====
1. Sort and display
2. Filter and display
3. exit
========================================
Enter your choice: 1
==================================================
1. Display files and directories by size
2. Display files by file type
3. Sort files/directories by date created
4. List files/directories by last modified date
5. Back
6. Exit
==================================================
Enter your choice: 1
Sort by Size:
1. Sort from large to small size
2. Sort from small to large size
Enter your choice: 1
------------------------ Sort by Size -----------------------
Size Date (Last Modified) File/Dir Name
-------------------------------------------------------------
330M 2023-10-05 jdk1.8.0_371
147M 2023-10-23 Nordzy-icon
137M 2023-10-05 jdk-8u371-linux-i586.tar.gz
120M 2023-10-17 thorium-browser_117.0.5938.157_amd64.deb
100M 2023-10-02 nomacs
100M 2023-10-03 JetBrainsMono.zip
94M 2023-10-02 jre-8u381-linux-x64.tar.gz
92M 2023-09-30 code_1.82.2-1694671812_amd64.deb
89M 2023-10-05 virtualbox-7.0_7.0.10-158379~Debian~bookworm_amd64.deb
86M 2023-10-01 balena-etcher_1.18.11_amd64.deb
77M 2023-09-30 firefox-118.0.1.tar.bz2
66M 2023-10-11 powershell_7.3.8-1.deb_amd64.deb
===============================================================
Sort by Size:
1. Sort from large to small size
2. Sort from small to large size
Enter your choice: 2
------------------------ Sort by Size -----------------------
Size Date (Last Modified) File/Dir Name
-------------------------------------------------------------
4.0K 2020-09-08 index.theme
4.0K 2023-10-01 Azeny.tar.gz
4.0K 2023-10-12 dwm-alwayscenter-20200625-f04cac6.diff
4.0K 2023-10-12 dwm-attachbottom-6.3.diff
4.0K 2023-10-12 dwm-uselessgap-20211119-58414bee958f2.diff
4.0K 2023-10-24 Noto Color Emoji
8.0K 2023-10-19 2.0.1alpha-fidir.sh
8.0K 2023-10-24 OFL.txt
12K 2023-10-12 dwm-alttab-6.4.diff
==================================================
1. Display files and directories by size
2. Display files by file type
3. Sort files/directories by date created
4. List files/directories by last modified date
5. Back
6. Exit
==================================================
Enter your choice: 2
========================= TXT Files =========================
Size Date (Last Modified) File/Dir Name
-------------------------------------------------------------
8.0K 2023-10-24 OFL.txt
========================= SH Files =========================
Size Date (Last Modified) File/Dir Name
-------------------------------------------------------------
16K 2023-10-16 install.sh
8.0K 2023-10-19 2.0.1alpha-fidir.sh
==================================================
1. Display files and directories by size
2. Display files by file type
3. Sort files/directories by date created
4. List files/directories by last modified date
5. Back
6. Exit
==================================================
Enter your choice: 3
-------------------- Sort by Date Created -------------------
Size Date (Created) File/Dir Name
-------------------------------------------------------------
8.0K 2023-10-24 OFL.txt
23M 2023-10-24 Noto Color Emoji.zip
4.0K 2023-10-24 Noto Color Emoji
147M 2023-10-23 Nordzy-icon
16M 2023-10-22 buuf-icons-plasma-2.0.8.tar.xz
8.0K 2023-10-19 2.0.1alpha-fidir.sh
120M 2023-10-17 thorium-browser_117.0.5938.157_amd64.deb
16K 2023-10-16 install.sh
7.9M 2023-10-14 picom
11M 2023-10-14 nvim-linux64.tar.gz
4.0K 2023-10-12 dwm-uselessgap-20211119-58414bee958f2.diff
880K 2023-10-12 dwm-bar
==================================================
1. Display files and directories by size
2. Display files by file type
3. Sort files/directories by date created
4. List files/directories by last modified date
5. Back
6. Exit
==================================================
Enter your choice: 4
----------------- Sort by Last Modified Date ----------------
Size Date (Last Modified) File/Dir Name
-------------------------------------------------------------
8.0K 2023-10-24 OFL.txt
23M 2023-10-24 Noto Color Emoji.zip
4.0K 2023-10-24 Noto Color Emoji
147M 2023-10-23 Nordzy-icon
16M 2023-10-22 buuf-icons-plasma-2.0.8.tar.xz
8.0K 2023-10-19 2.0.1alpha-fidir.sh
120M 2023-10-17 thorium-browser_117.0.5938.157_amd64.deb
16K 2023-10-16 install.sh
7.9M 2023-10-14 picom
11M 2023-10-14 nvim-linux64.tar.gz
4.0K 2023-10-12 dwm-uselessgap-20211119-58414bee958f2.diff
880K 2023-10-12 dwm-bar
==== FiDir - File Sort with Filters ====
1. Sort and display
2. Filter and display
3. exit
========================================
Enter your choice: 2
==================================================
1. Filter with file type
2. Filter by permission
3. Back
4. exit
==================================================
Enter your choice: 1
Enter the file type: sh
======================= sh Files =======================
Size Date (Last Modified) File Name
-------------------------------------------------------------
16K 2023-10-16 install.sh
8.0K 2023-10-19 2.0.1alpha-fidir.sh
==================================================
1. Filter with file type
2. Filter by permission
3. Back
4. exit
==================================================
Enter your choice: 2
Enter permission name (eg. write): w
====================== writable files ======================
Size Date (Last Modified) File Name
-------------------------------------------------------------
12M 2023-09-30 Gohu.zip
16K 2023-10-16 install.sh
4.8M 2021-12-07 lightdm-webkit2-theme-glorious-2.0.5.tar.gz
94M 2023-10-02 jre-8u381-linux-x64.tar.gz
44K 2023-10-05 solarized-dark.zip
2.0M 2023-10-01 Roboto.zip
8.0K 2023-10-24 OFL.txt
4.0K 2023-10-12 dwm-uselessgap-20211119-58414bee958f2.diff
==================================================
1. Filter with file type
2. Filter by permission
3. Back
4. exit
==================================================
Enter your choice: 2
Enter permission name (eg. write): r
====================== readable files ======================
Size Date (Last Modified) File Name
-------------------------------------------------------------
12M 2023-09-30 Gohu.zip
16K 2023-10-16 install.sh
4.8M 2021-12-07 lightdm-webkit2-theme-glorious-2.0.5.tar.gz
94M 2023-10-02 jre-8u381-linux-x64.tar.gz
44K 2023-10-05 solarized-dark.zip
2.0M 2023-10-01 Roboto.zip
==================================================
1. Filter with file type
2. Filter by permission
3. Back
4. exit
==================================================
Enter your choice: 2
Enter permission name (eg. write): x
====================== executable files ======================
Size Date (Last Modified) File Name
-------------------------------------------------------------
4.0K 2020-09-08 index.theme
==================================================
1. Filter with file type
2. Filter by permission
3. Back
4. exit
==================================================
Enter your choice: 4

9.0 Skill Developed / Learning outcome of this Micro-Project:


1. Shell Scripting: Proficiency in Bash scripting, including script design, development, and
implementation.
2. Problem Solving: The ability to identify and address challenges related to file management and
script development.
3. Linux Proficiency: Enhanced Linux efficiency by learning and understanding Linux concepts
especially file management.
4. Team Work: Working in a team environment for developing this project in collaboration.

10.0 Applications of Micro Project:


1. System Administration: Proficiency in shell scripting is invaluable for system administrators, as it
enables them to automate routine tasks, manage servers, and improve system efficiency.
2. Data Analysis: The ability to automate file processing is valuable for data analysts who work with
large datasets.
3. Personal Productivity: Apply these skills in your personal and professional life for increased
productivity and automation of routine tasks.

11.0 Name of Group Members:


Roll
Enrolment Seat No. Name of Students Student Signature
No.
2100780124 41 Patil Sanket Suresh
2100780127 44 Raut Mayur Hiraman
2100780130 47 Shimpi Jay Kiran
2105300263 63 Ahire Arpit Anil
Date: / / Evaluated by: Dated Signature of Guide: __________________
Name of Guide: Mrs. M. P. Bhosale

You might also like