Here is a practice exercise to help you become more familiar with using gzip:
- Create a sample text file in a text editor and save it to your computer.
- Open a terminal and navigate to the directory where the text file is located.
- Compress the file using gzip with the following command:Copy code
gzip filename.txt
This will create a compressed file with the “.gz” extension in the same directory as the original file. - Verify that the compressed file was created by using the “ls” command to list the files in the directory:bashCopy code
ls
You should see both the original text file and the compressed file with the “.gz” extension. - Decompress the file using the “gunzip” command:Copy code
gunzip filename.txt.gz
This will decompress the file and restore it to its original state. - Verify that the original file was restored by using the “ls” command to list the files in the directory:bashCopy code
ls
You should see only the original text file, with no “.gz” extension. - Create an archive of multiple files in the directory using tar and gzip with the following command:Copy code
tar czvf archive.tar.gz *
This will create an archive of all the files in the directory, compress it with gzip, and save it as “archive.tar.gz”. - Verify that the archive was created by using the “ls” command to list the files in the directory:bashCopy code
ls
You should see both the original text file and the compressed archive file with the “.tar.gz” extension. - Extract the contents of the archive to a new directory using the following command:Copy code
tar xzvf archive.tar.gz -C new_directory/
This will extract the contents of the archive to a new directory called “new_directory”.
By practicing these basic gzip commands, you can become more comfortable with using this powerful file compression and archiving tool on your Unix and Linux systems.