In: Computer Science
Write a brief shell script that will take in a specific file name, prompt the user whether they would like to gzip, bzip2, or xz compress the file. Depending on response, the script then ought to compress the provided file with the corresponding method
1). ANSWER :
GIVENTHAT :
To Write a brief shell script that will take in a specific file name, prompt the user whether they would like to gzip, bzip2, or xz compress the file. Depending on response, the script then ought to compress the provided file with the corresponding method
gzip compression reduce the size of a file and keeps the original file ownership, mode and timestamp. gzip will create a file filename.gz and delete the original file.
Syntax:
gzip [OPTION] [FILENAME]
bzip2 compression in Linux is used to compress a file and helps in binding the files into a single file which takes less storage space compared to the original file.
Syntax:
bzip2 [OPTIONS] [FILENAME]
xz compression is used to compress a file according to the selected operation mode and provides best compression. It supports various formats for file compression
Syntax:.
xz [OPTION] [FILENAME]
SCRIPT: #!/bin/sh touch dummy.txt # touch command creates an empty file with given name filename="dummy.txt" # Here path to the file can be given as value of a filename echo "enter 1 for gzip" echo "enter 2 for bzip2" echo "enter 3 for xz" read choice case $choice in "1") gzip $filename echo "gzip compression of $filename is completed!!" ;; "2") bzip2 -z $filename # option -z forces compression echo "bzip2 compression of $filename is completed!!" ;; "3") xz -z $filename echo "xz compression of $filename is completed!!" ;; *) echo "wrong choice" ;; esac