Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a bash script that accepts two command-line parameters: (1) a directory name, either absolute or relative, and (2) a size in bytes. For a

Write a bash script that accepts two command-line parameters: (1) a directory name, either absolute or relative, and (2) a size in bytes. For a valid directory, you will print out the list of files along with the size (in bytes) of each file only for those files whose size is greater than or equal to the size specified by the user in the command-line.

Your script must adhere to the following requirements:

If the user enters too few or too many arguments, you are to display an appropriate usage statement and terminate the program.

Since the directory given in the command-line may be absolute (e.g., $HOME/user/desktop) or relative (e.g., ../desktop), you must check that it is a valid directory. If the directory is not valid, you will print out an error message and terminate the program.

You must implement and use at least one non-trivial function in your bash script that accepts at least one parameter.

You must use at least one non-trivial sed or gawk command within your script. For use with these commands, you may wish to redirect some output from your script to a file called script.tmp and apply your sed and/or gawk command.

If no files match your criteria for the size of the file, you will print out some indicator that no files matched your criteria.

SAMPLE OUTPUT (user input shown in bold green):

$ ./test.sh

usage: ./test.sh directory size

$ ./test.sh some_directory

usage: ./test.sh directory size

$ ./test.sh bad_directory 100

error: unable to access bad_directory directory

$ cd testdir

./test.sh$ ls -l

total 36

-rw------- 1 user12 1743 Feb 11 17:02 elems.txt

-rw------- 1 user12 user12 50 Feb 11 17:02 numbers.txt

-rw------- 1 user12 user12 52 Feb 11 17:02 phone.txt

-rw------- 1 user12 user12 40 Feb 11 17:02 rec02.txt

-rw------- 1 user12 user12 2497 Feb 11 17:02 test1.c

-rw------- 1 user12 user12 2361 Feb 11 17:02 test2a.c

-rw------- 1 user12 user12 2336 Feb 11 17:02 test2.c

-rw------- 1 user12 user12 2598 Feb 11 17:02 test3.c

-rw------- 1 user12 user12 253 Feb 11 17:02 test.c

./test.shdir$ cd ..

$ ./test.sh testdir 100

Files with size greater than 100:

1 elems.txt 1743

2 test1.c 2497

3 test2a.c 2361

4 test2.c 2336

5 test3.c 2598

6 test.c 253

$ ./test.sh testdir 10

Files with size greater than 10:

1 elems.txt 1743

2 numbers.txt 50

3 phone.txt 52

4 rec02.txt 40

5 test1.c 2497

6 test2a.c 2361

7 test2.c 2336

8 test3.c 2598

9 test.c 253

$ ./test.sh testdir 2400

Files with size greater than 2400:

1 test1.c 2497

2 test3.c 2598

$ ./test.sh $HOME/user/desktop 2400

Files with size greater than 2400:

1 a.out 7477

2 minor2.c 4074

3 test1.c 2497

4 test3.c 2598

5 testdir 4096

$ ./test.sh ../desktop 4000

Files with size greater than 4000:

1 a.out 7477

2 minor2.c 4074

3 testdir 4096

$ ./test.sh ../desktop 10000

Files with size greater than 10000:

-- NONE --

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

Semantics Of A Networked World Semantics For Grid Databases First International Ifip Conference Icsnw 2004 Paris France June 2004 Revised Selected Papers Lncs 3226

Authors: Mokrane Bouzeghoub ,Carole Goble ,Vipul Kashyap ,Stefano Spaccapietra

2004 Edition

3540236090, 978-3540236092

Students also viewed these Databases questions

Question

Explain the importance of nonverbal messages.

Answered: 1 week ago

Question

Describe the advantages of effective listening.

Answered: 1 week ago

Question

Prepare an employment application.

Answered: 1 week ago