Question

write the bash script Write a script compress_large_files.sh. This script accepts one or more command line...

write the bash script

Write a script compress_large_files.sh. This script accepts one or more command line arguments. 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 ...] 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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#/bin/bash
size=$1
PASSED=$2

re='^[0-9]+$'
if ! [[ $size =~ $re ]] ; then
echo "ERROR: $size is not a number" >&2;
exit 1
fi

if ! [[ -d "${PASSED}" ]] ; then
echo "ERROR: $2 is not a directory" >&2;
exit 1
fi

if ! [[ -r $PASSED ]];
then
echo "ERROR: Cannot read file $PASSED"
exit 1
else
find $PASSED -type f ! -name '*.gz' -exec gzip "{}" \;
fi

there is some modification still remain you just check it out and let me know where changes needed as far as i know only size thing is remain because i do not know what it try to say as far as i know its saying that if size is 10 then less than 10 mb of file size should be zipped or greater than of 10 mb should be zipped ?

if you have any doubt then please ask me without any hesitation in the comment section below , if you like my answer then please thumbs up for the answer , before giving thumbs down please discuss the question it may possible that we may understand the question different way and we can edit and change the answers if you argue, thanks :)

Add a comment
Know the answer?
Add Answer to:
write the bash script Write a script compress_large_files.sh. This script accepts one or more command line...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a bash shell script called direct.sh. This script will take an arbitrary number of command...

    Write a bash shell script called direct.sh. This script will take an arbitrary number of command line arguments. Your script should create directories starting with the first argument, then the second directory inside the first one, and then the next one inside the second one, and so on.

  • Write a script using simple shell commands. The script takes a command line argument that specifies...

    Write a script using simple shell commands. The script takes a command line argument that specifies a directory dir. The script first changes directory to dir, then prints the following in sequence: (a) A line starting “Current date and time: ”. Then on the same line, the current time and date. (b) A line starting “Current directory is : ”. Then, on the same line, the absolute pathname of the current working directory. (c) An empty line (d) The line...

  •  Write a Perl script that accepts exactly 2 integer arguments where the first argument must...

     Write a Perl script that accepts exactly 2 integer arguments where the first argument must be less than the second argument. The script will print a comma separated list of integers starting with the first argument up through the second argument.  The last printed value should be the second command line argument not be followed by a comma.  The script should also be able to handle the following errorsituations: o incorrect number of arguments o the first...

  • 1.Write a bash script A5p1.sh to output the number of executable and non-executable files and subdirectories...

    1.Write a bash script A5p1.sh to output the number of executable and non-executable files and subdirectories separately in the directory that is specified as the first command line argument to this script. Do not count recursively in subdirectories. Do not call any external Linux utilities such as “ls”. 2.Write a bash script A5p1.sh to output the number of executable and non-executable files and subdirectories separately in the directory that is specified as the first command line argument to this script....

  • LINUX 140U Create a file named script1.sh that contains a bash script that: Accepts NO command...

    LINUX 140U Create a file named script1.sh that contains a bash script that: Accepts NO command line arguments and does NOT use the read command. I will give you no credit if your bash script includes a read command. Also, you need to have at least one for..in loop in your code even if there may be other ways to do this problem. The script will go through a list of entries in the current directory (do not process subdirectories):...

  • Write a bash shell script, deleteFilesWithZeroLength.sh, that removes all zero length ordinary files in the directory passed as an optional argument. If you do not specify the directory argument, the script uses the present working directory as the defaul

    Write a bash shell script, deleteFilesWithZeroLength.sh, that removes all zero length ordinary files in the directory passed as an optional argument. If you do not specify the directory argument, the script uses the present working directory as the default argument. Do appropriate exception handling in your script such as:If the arguments are more than 1, print out “Too many arguments passed”.If the argument passed is a regular file, print out “XXX is regular file”.1c. If the directory doesn’t exist, print out “Directory...

  • write a bash script that will take one or more directory names as arguments and count...

    write a bash script that will take one or more directory names as arguments and count the number of .txt files under each one (that is the number of .txt files in each subdirectory, subdirectories and so on).

  • Part 1: Create a shell script that returns a full name associated with a userid specified...

    Part 1: Create a shell script that returns a full name associated with a userid specified in the command line argument. • Use the names found in /acct/common/CSCE215-Spring19. • Your shell script should be named “findName.sh” – Example usage: $ ./findName.sh seiei SETSUNA F SEIEI $ – Your shell script must either: Return the full name associated with the userid or Return an error message if the command line arguments are not equal to 1. or Return the message “Sorry...

  • Problem 4: Write a Bash script that removes all zero length ordinary files in the directory...

    Problem 4: Write a Bash script that removes all zero length ordinary files in the directory (including those in the sub-directories at all levels) passed as an optional argument. If you do not specify the directory argument, the script uses the current working directory as the default argument. This problem is for practicing bash programming skills. Though there is an easier way to achieve the goal with the find command, the find command is not allowed to appear in your...

  • Command line input In C++ it is possible to accept command line arguments. Command-line arguments are...

    Command line input In C++ it is possible to accept command line arguments. Command-line arguments are given after the name of a program in command-line operating systems like Linux and are passed in to the program from the operating system. To use command line arguments in the program, it must first understand the full declaration of the main function, which until now has accepted no arguments. In fact, main can accept two arguments: one argument is number of command line...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT