Archiving
Archiving means combining multiple files into one single file. It does not reduce file size, it simply packages everything together.
tar - command use to create the archive.
I practiced creating an archive using:
tar -cvf archive.tar proj_dir
What -cvf means:
-
c- tells tar to create a new archive. -
v- verbose (show progress). -
f- file name. This creates one file called archive.tar that contains everything insideproj_dir.
Compression
Compression reduces files size to save storage space and make file transfers faster.
gzip - command use to compress file size.
Example:
gzip archive.tar
This command will compress archive.tar and rename it to archive.tar.gz. The original archive.tar file will be replaced by the compressed version.
This created:
archive.tar.gz
Archiving + Compressing Together
What I found really useful is that we can archive and compress at the same time:
tar -czvf archive.tar.gz sample_dir
The new option here is:
z - use gzip compression
This command:
- Combines the folder
- Compresses it
- Creates a
.tar.gzfile
Now I understand why .tar.gz files are so common in Linux systems.
Extracting Files
To extract a compressed archive:
tar -xzvf archive.tar.gz
- x = extract
- z = gzip
- v = verbose
- f = file This restores everything from the archive.
Today, I learned that archiving combines multiple files into one using tar without reducing file size, while compression reduces the file size with tools like gzip. I practiced creating an archive with tar -cvf archive.tar proj_dir and compressing it using gzip archive.tar to make archive.tar.gz. I also learned that I can archive and compress at the same time with tar -czvf archive.tar.gz sample_dir. Finally, I practiced extracting files using tar -xzvf archive.tar.gz.
Top comments (0)