Lab 4 Solutions
Lab 4 Solutions
Pre-Lab
Tar, gzip
Commands
1. Create a directory named testdir. Inside testdir, create files named
file1.txt, file2.txt, and file3.txt. Use the tar command to create an archive
named testdir.tar of the testdir directory. List the contents of the
testdir.tar archive without extracting it.
tar is a Linux/Unix command-line utility used for combining multiple files and directories into a
single archive file. This archive, often referred to as a tarball, typically has a .tar extension. tar is
useful for creating backups or grouping files for easier storage or transfer. However, a .tar file is
not compressed by default; it only bundles files together.
gzip is a command-line utility used to compress files, reducing their size for storage or transfer.
The resulting compressed file typically has a .gz extension. gzip is often used in conjunction with
tar to create compressed archives, commonly referred to as .tar.gz files.
mkdir testdir
tar -tvf testdir.tar: Lists the contents of the testdir.tar archive without extracting it.
mkdir extracted
tar -xvf testdir.tar -C extracted/: Extracts the contents of testdir.tar into the extracted
directory. The -C option specifies the directory where the files should be extracted.
# Step 1: Create a text file named sample.txt with some sample text
gzip sample.txt
ls -l
ls -l: Lists the contents of the directory, showing the compressed file sample.txt.gz.
gunzip sample.txt.gz
ls -l
ls -l: Lists the contents of the directory, confirming that sample.txt has been restored.