Manage compressed or compressed folders using a Linux terminal

Sometimes when you need create .zip archive on Linux car, it’s not as easy as in the windows. Every time you need to download more files or lots of tasks, or even when you need a backup for a website, you need to learn some basic commands for archiving and unzipping folders on Linux. To compress archive files, we use the zip command. This is a utility for compressing and packing files. We also have unzip, which is used to unzip zip archives. This tutorial will help you learn how to compress and manage folders on Ubuntu Linux using the command line.

Zip or compress folder

To compress, we first need to install the zip command, for which we will use “apt teamorapt-get commandSo, now we will open the terminal to install the zip command.

Step 1:

After opening the terminal, write the command “sudo apt install zip unzip“To install the zip command.

Enter the required credentials.

Manage compressed or compressed folders using a Linux terminal

Installation begins, and the command line looks like this. In a few seconds it will be done.

Manage compressed or compressed folders using a Linux terminal

Step 2:

The next step is to compress the necessary files using the zip command. We want to compress a folder called TestDir, whose current directory is Desktop.

Manage compressed or compressed folders using a Linux terminal

Manage compressed or compressed folders using a Linux terminal

Therefore, on the command line in Linux, we will also change our current directory to the desktop. Manage compressed or compressed folders using a Linux terminal

We can see the current folders on the desktop using the ls command.

Manage compressed or compressed folders using a Linux terminal

The file we want to compress is also on the list. Manage compressed or compressed folders using a Linux terminal

We use the command “zip –r folderName folder”To which we want to compress our folder.

Manage compressed or compressed folders using a Linux terminal

Manage compressed or compressed folders using a Linux terminal

In the end, a compressed TestDirTerminal.zip is created, which we wanted to create by compressing our TestDir folder so that we can see that it was created.

Manage compressed or compressed folders using a Linux terminal

Manage compressed or compressed folders using a Linux terminal

The folder we wanted to compress was compressed.

Step 3:

We can also compress files using the command line on Linux. We selected a folder, Testfolder for this and file Testfile as you can see. Both are again on the desktop. In this step, we compress the file and folder, respectively.

Manage compressed or compressed folders using a Linux terminal

Manage compressed or compressed folders using a Linux terminal Manage compressed or compressed folders using a Linux terminal

We will move our current directory to the desktop if it has not been selected previously. After that, we see the elements of the directory using the “dir” command. We can find everything that interests us, where TestFolder and TestFile are also listed.

Manage compressed or compressed folders using a Linux terminal

In order to compress the folder, we will use the following command.

Manage compressed or compressed folders using a Linux terminal

This will archive the folder.

In the same way we want to compress the file, we will use the following command as follows.

Manage compressed or compressed folders using a Linux terminal

This will archive our TestFile.

After creating TestFile and Testfolder.zip can be seen on the desktop.

Manage compressed or compressed folders using a Linux terminal

Manage compressed or compressed folders using a Linux terminal Manage compressed or compressed folders using a Linux terminal

We can also use Gzip The command to compress the file, as we did with Grocery list.

Manage compressed or compressed folders using a Linux terminal

The result shows that GroceryList.gz was created on Desktop catalog,

Manage compressed or compressed folders using a Linux terminal

Manage compressed or compressed folders using a Linux terminal

For too many files, we will use the tar command. Here we have a GroceryList, so for this we will use tar cvf

C: Create

V: display output in terminal (used for verification)

F: Only for fire options

Manage compressed or compressed folders using a Linux terminal

We can always use the ls command to check. Here, as you can see, GroceryList.tar was created.

Manage compressed or compressed folders using a Linux terminal

Manage compressed or compressed folders using a Linux terminal

Unzip the compressed folder:

To unzip the file, we will use the command, unzip, But first we need to install the unpacked code, as we did earlier for archiving. We use the team sudo apt-get install unzip for this. The command is used as

Manage compressed or compressed folders using a Linux terminal

Enter your credentials:

Manage compressed or compressed folders using a Linux terminal

This will be installed in the end. You can see the following commands on the screen while you run them at our own end.

Manage compressed or compressed folders using a Linux terminal

For the zip command

First, we will extract our files for zip files. Since in the list above you can see the first example we compressed is listed there as a compressed file “TestDirTerminal.zip“, Now we compress this file with the unzip command. Here we write the unzipped file and the name of the file we want to unzip.

Manage compressed or compressed folders using a Linux terminal

We will see that

Manage compressed or compressed folders using a Linux terminal

Manage compressed or compressed folders using a Linux terminal

Manage compressed or compressed folders using a Linux terminal

The tar file will have a different methodology, we will use another method that we used in compression, so it is very similar to this, but here, to extract the tar file, we will use tar xvf,

Where x: means extract

V: for checking, as we saw earlier

F: for fire

Here we had a tar file named “GroceryList.tar”, so we unpacked it with the following command.

Manage compressed or compressed folders using a Linux terminal

The command helps us extract the files, and as soon as they are extracted, we can also view the result using the ls command for the current directory. So, here is the extracted file.

Manage compressed or compressed folders using a Linux terminal

Manage compressed or compressed folders using a Linux terminal

To check and view the list of contents in the tar file, we use the tar –tvf command and add the name of the tar file whose contents we want to see. As a result, we get a list of archive contents on our screens. Thus, the following command will be used to view the archived content in a specific tar file.

Manage compressed or compressed folders using a Linux terminal

Conclusion

In this tutorial, we saw how to create compressed folders / files on the Linux command line. We also learned how to extract source files from compressed on the Linux command line. We also noticed that for the parallel check we use the ls command, regardless of whether the file was created or not. The file extension lets us know if it was compressed or not, if so, whether it is zip, tar or gz. Finally, we saw how we can view the contents archived in a specific tar file.

Manage compressed or compressed folders using a Linux terminal

Sidebar