Created
November 18, 2024 05:47
-
-
Save LeetIDA/085e342a23aef8d99a3df97109b856ac to your computer and use it in GitHub Desktop.
Lab8 Solved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script name: findBigFiles.sh | |
# Author: Husain Alderazi | |
# Date: 13/11/2024 | |
# Purpose: Find files larger than a specified size in the current directory | |
function usage { | |
echo "***************************************" | |
echo "USAGE: $SCRIPT_NAME [Number_Of_Meg_Bytes]" | |
echo "EXAMPLE: $SCRIPT_NAME 5" | |
echo "Will Find Files Larger Than 5 Mb in and below the Current Directory..." | |
echo "EXITING..." | |
echo "***************************************" | |
} | |
function trap_exit { | |
echo -e "\n**********************************************" | |
echo -e "\n\n EXITING ON A TRAPPED SIGNAL..." | |
echo -e "\n\n**********************************************\n" | |
} | |
trap 'trap_exit; exit 2' 1 2 3 15 | |
if [ $# -ne 1 ]; then | |
usage | |
exit 1 | |
fi | |
DATESTAMP=$(date +"%h %d,%Y,%T") | |
SEARCH_PATH=$(pwd) | |
echo "Searching for Files Larger Than $1Mb starting in:" | |
echo "$SEARCH_PATH" | |
echo "Date: $DATESTAMP" | |
echo "Please Standby for the Search Results..." | |
find "$SEARCH_PATH" -type f -size +"$1"M -print > results.out | |
if [ ! -s results.out ]; then | |
echo "No files were found that are larger than $1Mb" | |
echo "Exiting..." | |
exit 0 | |
fi | |
num_files=$(wc -l < results.out) | |
echo "Number of files found: $num_files" | |
#echo "Results are in the file: results.out" | |
cat results.out | |
rm results.out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment