Here’s what those flags (-cvf) actually mean
-c, —create – create a new archive
-x, —extract, —get – extract files from an archive
-f, —file ARCHIVE – use archive file or device ARCHIVE
Create tar.gz or tgz Archive File by Compressing an Directory or a Single File
The terminal command below will create a .tar.gz file called sample_dir.tar.gz with a directory /home/codebind/sample_dir or sample_dir in present working directory.
Notice that we have added extra flag -z to the command.Here’s what the flag -z actually mean
-z, —gzip, —gunzip —ungzip – Compress the archive with gzip
ripon@ripon:~$ tar -cvzf sample_dir.tar.gz sample_dirsample_dir/ sample_dir/main.cpp sample_dir/sample.png sample_dir/output ripon@ripon:~$ ls sample_dir sample_dir.tar.gz
The command bellow will create a .tgz file. One this to notice is tar.gz and tgz both are similar.
ripon@ripon:~$ tar -cvzf sample_dir.tgz sample_dirsample_dir/ sample_dir/main.cpp sample_dir/sample.png sample_dir/output ripon@ripon:~$ ls sample_dir sample_dir.tgz
Compressing Multiple Directories or Files at Once
Let’s say, For example we want to compress the sample_dir directory, the java_test directory, and the abc.py file to a tar file called sample_dir.tar.gz .
Run the following command to achieve the goal above.
ripon@ripon:~$ tar -cvzf sample_dir.tar.gz sample_dir java_test abc.py sample_dir/ sample_dir/main.cpp sample_dir/sample.png sample_dir/output java_test/ java_test/HelloCV.java abc.py ripon@ripon:~$ ls sample_dir java_test abc.py sample_dir.tar.gz
Create .bzip2 Archive File by Compressing an Directory or a Single File
ripon@ripon:~$ tar -cjvf sample_dir.tar.bz2 sample_dir sample_dir/ sample_dir/main.cpp sample_dir/sample.png sample_dir/output ripon@ripon:~$
Notice that we have added extra flag -f to the command.Here’s what the flag -f actually mean
-f, —file ARCHIVE – use archive file or device ARCHIVE
Extract .tar Archive File
We can extract or untar the compressed file using the tar command. The command below will extract the contents of sample_dir.tar to the present directory.
ripon@ripon:~$ tar -xvf sample_dir.tar sample_dir/ sample_dir/main.cpp sample_dir/sample.png sample_dir/output ripon@ripon:~$
The following command will extract or untar files in specified Directory i.e. /home/codebind/dir_name in this case.
ripon@ripon:~$ tar -xvf sample_dir.tar -C /home/codebind/dir_name sample_dir/ sample_dir/main.cpp sample_dir/sample.png sample_dir/output ripon@ripon:~$
we have added extra flag -C to the command.Here’s what the flag -C actually mean
-C, —directory DIR – change to directory DIR
Ever found yourself in a situation where you’ve downloaded a zipped file on your Linux system and you’re scratching your head, wondering how to set the contents free? Fear not, brave adventurer! This guide will equip you with not one, not two, but five different ways to unzip files in Linux. By the end of it, you’ll be unzipping files faster than a kangaroo on a trampoline!
We are focusing on the Ubuntu variant in this how to guide however these methods will work with most linux distributions.
For those who prefer to point and click rather than type, the File Roller (or Archive Manager) is your trusty steed.
Ah, the classic unzip command. It’s like the Swiss Army Knife of unzipping files—always handy, and always gets the job done.
Another method that requires no new software is to use firefox browser and our very own ezyZip online unzipper.
Meet 7-Zip, the Hercules of file compression tools. You’ll need to install it first, though.
With Ezriah’s expertise, navigating the intricacies of file compression and understanding the functionalities of archiving becomes a breeze. From crafting step-by-step tutorials to creating in-depth videos, Ezriah brings complex technical concepts to life, making them accessible to users of all levels of expertise. Ezriah represents the collective wisdom of the entire ezyZip team.
Adblock