Let’s start with the basics. In Linux, compressing and decompressing files is a regular task. The tar tool is one of the most popular for this job. You can think of tar as a way to pack and unpack files.
To use tar, you need to know its arguments. Don’t worry, it’s easy to learn. You can find all the documentation for a command by using man <command>. For tar, some important arguments are:
- `c` – create a new file
- `p` – preserve permissions
- `z` – compress the file using gzip
- `f` – specify the file
- `v` – verbose mode, shows everything on the screen
- `x` – extract
- `j` – bzip2
Now, let’s look at some examples to make it easier to understand.
Compressing Files
To archive the entire /root/Blaze Trends directory into Blaze Trends.tar, you would use:
tar -cf Blaze Trends.tar /root/Blaze Trends |
For archiving Blaze Trends1 and Blaze Trends2 into Blaze Trends.tar with verbose mode:
tar -cvf Blaze Trends.tar Blaze Trends1 Blaze Trends2 |
To create a compressed file Blaze Trends.tgz (zip):
tar czfP Blaze Trends.tgz /root/Blaze Trends |
And to create a compressed file Blaze Trends.tbz (bzip2):
tar -cjf Blaze Trends.tbz /root/Blaze Trends |
Decompressing Files
To extract Blaze Trends.tar, you simply use the x argument. For Blaze Trends.tgz (zip) or Blaze Trends.tbz (bzip2), you would use the corresponding compression argument along with x. For example, to extract Blaze Trends.txt from Blaze Trends.tar.gz, you would use:
tar -xzf Blaze Trends.tar.gz Blaze Trends.txt |
It might seem complicated at first, but understanding the arguments makes it straightforward. If you have any doubts or tips, feel free to share them in the comments for the benefit of the community.
