Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help me with this bash programming assignment in Linux 1) Write a script named long_file.sh to find the longest file name in a

Can someone help me with this bash programming assignment in Linux

1) Write a script named long_file.sh to find the longest file name in a

directory. long_file.sh will accept a directory name as the first argument

and determine the longest filename in that directory.

If the correct number of arguments are not provided, print an error message to

standard output and exit the script with a return error of 1. If the scripts's

first argument is not a directory name, print an error message to standard

output and exit with a return code of 1.

If a the first argument is a directory, print the directory name prior to

printing the longest filename and length.

If there are multiple files with the same length, you may print the first one

found. You may print multiple filenames for 5 bonus points.

Rubric: 50 points

Correct script name: 5

Check for valid parameters: 5 points

Check for directory: 5 points

Print out correct filename: 5 points

Print out correct length: 10 points

(Documentation) Reasonable comments in code 10

(Coding standards) Accepted programming standard and conventions 10

Undergraduate students (+5 if finding multiple filenames is implemented.)

2) Write a script named count_files.sh which counts the number of ordinary

files, directories, and number of empty files in a directory. count_files.sh

accepts a directory name as the first parameter. Print to standard output the

following information about the directory: Number of ordinary files, number of

directories, and number of empty files. If the correct number of arguments are

not provided, print an error message to standard output and exit the script with

a return error of 1. If the scripts's first argument is not a directory name,

print an error message to standard output and exit with a return code of 1.

If a the first argument is a directory, print the directory name prior to

printing the longest filename and length.

Rubric: 50 points

Correct script name: 1

Check for valid parameters: 4 points

Check for directory: 5 points

Print out text for ordinary files 1

Print out correct number of ordinary files 4

Print out text for directories 1

Print out correct number of directories 4

Print out text for number of empty files 1`

Print out correct number of empty files 4

Print out text for total number of files 1

Print out correct number total number of files 4

(Documentation) Reasonable comments in code 10

(Coding standards) Accepted programming standarrd and conventions 10

3) Place both of these scripts in a tarball (compressed tar file) that follows

our class conventions (LastName-FirstName-Assign4.tar.gz) and upload to blackboard.

In both scripts, be sure to check for the proper usage parameters.

Hints:

** You can implement however you want, but here are some tips.

1) You can execute an ls command to get a list of files.

2) You can use a for..in control structure to loop through the list of

files. Remember that ls without flags does not return the full path of the

file. You may have to append the path to the beginning of the filename to use

the test command. I recommend using a for..in control structure so that you

get practice using this control structure.

3) Remember to use arithmetic expression syntax when accumulating counters.

4) Do not count the current dir (.) and the parent directory (..) files.

5) You can use the following flags with test to check the status of the files.

-f for ordinary file

-d for directory

! -s for empty files (empty file is a file with size=0)

6) Consider using ${#filename} to determine the file length.

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

Recommended Textbook for

Handbook Of Relational Database Design

Authors: Candace C. Fleming, Barbara Von Halle

1st Edition

0201114348, 978-0201114348

More Books

Students also viewed these Databases questions