Unzip or unzip multiple files at the same time in Debian 10

File compression is a way to create archives that helps us save time, free up space, and speed up downloading and transferring software and data. You can use the compressed file to distribute related files on the Internet, they will all be compressed into one file without any data loss. If you need space on your system or on an external storage device, you can compress the files into smaller archive files. Sometimes we have to extract several zipped and rar’d files at once, all of them are in one folder. It is quite easy to do this through the Linux user interface; all you have to do is select all the files you want to extract, right-click and use the extract option to extract them completely. The real problem is when we want to perform the same task via the command line. Extracting files one at a time, typing the extract commands one by one, can be quite lengthy and downright illogical. And here is the bash rescue loop. You can use it to perform several similar operations at the same time.

This article describes how you can use a for loop to extract multiple files of the following type via the Debian command line:

  • ZIP files
  • Tar.xz files
  • Rar files
  • 7z files

We have followed the commands and procedures mentioned in this article on a Debian 10 Buster system. We are using the Terminal application as the Debian command line. You can open it by searching for Application Launcher as follows:

The Application Launcher can be accessed using the Windows / Super key on your keyboard.

Unzip multiple files at the same time

Suppose a folder, in our case the “zip_files” folder, contains multiple zipped files and we want to extract them at the same time.

Unpack multiple files

Here’s how you can use a for loop to make things easier:

$ for z in *.zip
do
unzip $z;
done

Use a bash script loop to unpack multiple files

This is how you can accomplish the same task with a single command:

$ for z in *.zip; do unzip "$z"; done

Unzip multiple files at once

Extract multiple tar.xz files at once

Suppose a folder contains multiple tar.xz files and we want to extract them at the same time.

Here’s how you can use a for loop to make things easier:

$ for z in *.tar.xz
do
tar -xf $z;
done

Use a bash loop to unpack files

This is how you can accomplish the same task with a single command:

$ for z in *.tar.xz; do tar -xf "$z"; done

Unzip multiple files at the same time

Use the following command to unpack multiple rar files at once.

$ for z in *.rar
do
unrar e $z;
done

Or,

$ for f in *.rar; do unrar e “$f”; done

Extract multiple 7z files at the same time

Use the following command to extract multiple 7z files at the same time.

$ for z in *.7z
do
7z e $z;
done

Or,

$ for z in *.7z; do 7z e "$z"; done

Using a bash for loop, you can perform the complex task of extracting multiple compressed files at the same time. This little skill that you learned in this article is especially useful when we need to extract up to hundreds of compressed files at the same time. Not only for fetching files, but you can also use the power of bash’s “for” loop to perform various other similar tasks that can take longer if you run them one at a time.

Unzip or unzip multiple files at the same time in Debian 10

Sidebar