Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The BASH script you are going to write for this problem is supposed to do severa

ID: 3877348 • Letter: T

Question

The BASH script you are going to write for this problem is supposed to do several things. Unzip the "zip_directory. tar .gz" file. (You need a specific command for uncompressing/compressing tar. gz files.) From the unzipped directory, the script should move the files whose names have the sulfix". txt" to a directory named "TXT". From the unzipped directory, the script should move the files whose names end with ".jpg" to a directory named "JPG". From the unzipped directory, the script should move the rest of the files to a directory named "ZIP". The ZIP directory should then be compressed and named "zip_di rectory_zipped, tar.gz". Finally, the script should remove the directory named ZIP (not the compressed one). Please name your script "problem10.sh".

Explanation / Answer

problem10.sh

#!/bin/bash

tar -xzf zip_directory.tar.gz   # unzip the zip_directory.tar.gz file.

#Here, -x option tells tar to extract the files. -z option tells the tar to uncompress the file. -f option #tells tar that you are providing a file name to work with.

mkdir TXT # create directory named TXT to store the .txt files

mv zip_directory/*.txt TXT # moving .txt files from uncompressed zip_directory to TXT

mkdir JPG # create directory named JPG to store .jpg files

mv zip_directory/*.jpg JPG # moving .jpg files from uncompressed zip_directory to JPG

mkdir ZIP # create directory named ZIPto store remaining files

mv zip_directory/* ZIP # moving remaining files from uncompressed zip_directory to ZIP

tar -czf zip_directory_zipped.tar.gz ZIP # compressing ZIP directory

# Here -c option tells the tar to create an archive. -z tells the tar to compress the archive with gzip. -f tells #the tar that you are providing with the filename to work with.

rm -rf ZIP # deletes the directory ZIP(uncompressed) with all its contents

Run the script on the terminal : sh problem10.sh