Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My shell script is below: I'm trying to add a for loop to script, but I don't know where to add it. I'm not sure

My shell script is below: I'm trying to add a for loop to script, but I don't know where to add it. I'm not sure if my script is correct or if I am doing something wrong. I writing this in unix scripting.

Write a script using the bash shell to find and print a long listing for all files that are over a specified size and files that were modified more than a specified number of days ago. Each section of files listed should be preceded by a heading indicating what listing follows. The usage of this script should be Filename.bash [starting directory] [minimum filesize in KB] [age for files in days]

Note that all command-line arguments are optional. If you dont include the command-line argument, the following defaults should be used in the script:

Directory current directory

Minimum filesize 1 KB

Age for files 90 days

Requirements for the script:

Must have a usage clause

Must accept up to three arguments, but can accept zero

Must use a case statement for assigning CLAs/default values to variables

Must use the find command without the -exec or -ls options

Must use a for loop to process files returned by find

display_usage() { echo -e " Usage:" echo "$0 [Current directory] [Minimum filesize in KB] [Age for files in days]" }

#if statement if [ $# -gt 3 ] then display_usage exit 1 fi

#dir (directory) for the printing working directory dir=$PWD #dir minfilesize=1 ageofFile=90

#case staement case $# in 1) dir=$1 ;;

2) dir=$1 minfilesize=$2 ;;

3) dir=$1 minfilesize=$2

find $dir -size +${minfilesize}k -type f -mtime +$ageofFile -print

Here is the for loop:

files=`/bin/ls .` for file in $files do if [ -d $file ]; then echo $file fi done

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions