Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(a) Write a script compress_large_files.sh. This script accepts one or more command line argu- ments. The first argument has to be an integer; let's call

image text in transcribedimage text in transcribed

(a) Write a script compress_large_files.sh. This script accepts one or more command line argu- ments. The first argument has to be an integer; let's call it size. If this is the only command line argument, compress_large_files.sh inspects all files in the current working directory and compresses every file of size at least size. If there is more than one command line argument, all arguments except the first one must be valid directories. In this case, compress_large_files.sh inspects the files in each of these directories and, once again, compresses every file of size at least size. If successful, your script should not produce any output on stdout. You script should produce the following error messages: If the wrong number of command line arguments is given, a usage message USAGE : compress-large-files. sh size [dir J should be printed . If the first argument is not a number, a message ERROR: xxx is not a number should be printed, where xxx is the argument provided by the user. If any argument other than the first one is not a valid directory, a message ERROR: Xxx is not a directory should be printed, where xxx is the argument in question. If a directory to be searched for files or a file in such a directory cannot be read, a message ERROR: Cannot read file xxx should be printed, where xxx is the file or directory in question. Subdirectories of the current working directory or of the directories provided on the command line should not be search recursively and should be ignored silently. (b) Write a script view.sh that takes one or more command line arguments. Each argument must be the name of a readable file. For each argument, view.sh should check whether this is a file that was compressed using gzip. If so, it should uncompress it using gunzip and display the result using cat. (You may also explore whether gunzip can display its output directly, without usin,g cat as a helper.) If the file was not compressed using gzip, the file should be displayed without decompressing it. There are two important requirements for view. sh: While the default behaviour of gunzip is to delete the file.gz file it is given and create the uncompressed file file from it, view.sh is not allowed to do this. There are many ways to achieve this. One of them is to copy the file to be decompressed into the /tmp directory, decompress it there, display it, and delete it from /tmp. Second, view.sh should display only the contents of the files that were passed to it. For each file that cannot be read, it should print an error message ERROR: Cannot read file xxx, where xxx is the file in question. No other output must be produced. Most of this question should be straightforward. There are two parts that require some creativity: How to check whether a file is compressed? gunzip can help you with that. Just try to run it on the given file. If the file is a gzipped file, this just works. Otherwise, it fails and gunzip lets you know via its exit code. The previous suggestion leads to another wrinkle: when gunzip fails, it happily informs us with an error message, but view.sh is not allowed to produce any output other than its own error messages. You need to figure out how to silence gunzip. man gunzip and a careful read of that manpage and a Google search for /devull lead you to two possible ways to do this. (a) Write a script compress_large_files.sh. This script accepts one or more command line argu- ments. The first argument has to be an integer; let's call it size. If this is the only command line argument, compress_large_files.sh inspects all files in the current working directory and compresses every file of size at least size. If there is more than one command line argument, all arguments except the first one must be valid directories. In this case, compress_large_files.sh inspects the files in each of these directories and, once again, compresses every file of size at least size. If successful, your script should not produce any output on stdout. You script should produce the following error messages: If the wrong number of command line arguments is given, a usage message USAGE : compress-large-files. sh size [dir J should be printed . If the first argument is not a number, a message ERROR: xxx is not a number should be printed, where xxx is the argument provided by the user. If any argument other than the first one is not a valid directory, a message ERROR: Xxx is not a directory should be printed, where xxx is the argument in question. If a directory to be searched for files or a file in such a directory cannot be read, a message ERROR: Cannot read file xxx should be printed, where xxx is the file or directory in question. Subdirectories of the current working directory or of the directories provided on the command line should not be search recursively and should be ignored silently. (b) Write a script view.sh that takes one or more command line arguments. Each argument must be the name of a readable file. For each argument, view.sh should check whether this is a file that was compressed using gzip. If so, it should uncompress it using gunzip and display the result using cat. (You may also explore whether gunzip can display its output directly, without usin,g cat as a helper.) If the file was not compressed using gzip, the file should be displayed without decompressing it. There are two important requirements for view. sh: While the default behaviour of gunzip is to delete the file.gz file it is given and create the uncompressed file file from it, view.sh is not allowed to do this. There are many ways to achieve this. One of them is to copy the file to be decompressed into the /tmp directory, decompress it there, display it, and delete it from /tmp. Second, view.sh should display only the contents of the files that were passed to it. For each file that cannot be read, it should print an error message ERROR: Cannot read file xxx, where xxx is the file in question. No other output must be produced. Most of this question should be straightforward. There are two parts that require some creativity: How to check whether a file is compressed? gunzip can help you with that. Just try to run it on the given file. If the file is a gzipped file, this just works. Otherwise, it fails and gunzip lets you know via its exit code. The previous suggestion leads to another wrinkle: when gunzip fails, it happily informs us with an error message, but view.sh is not allowed to produce any output other than its own error messages. You need to figure out how to silence gunzip. man gunzip and a careful read of that manpage and a Google search for /devull lead you to two possible ways to do this

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

Question

What is meant by 'Wealth Maximization ' ?

Answered: 1 week ago