Unzip all file in directory linux

How to Zip and Unzip a directory and its files in Linux [duplicate]

I am a newbie in Linux.Whats is the complete process to zip and unzip a directory and its files.Please mention if any installation has to be done.

3 Answers 3

You say you are a newbie. Maybe you got Windows-experiences. If you do not have the packages installed yet, you need to

sudo apt-get install zip gzip tar 

first (or by a graphical pkg-manager).

Then, for an entry it would be the easiest way to use zip/unzip:

zip -r my_arch.zip my_folder 

Zip stores relative path names by default. There are several parameter-options available for zip. For that read: the manual (man zip). For a starting this will do.

Most often you will see .tar.gz endings in linux-world. That’s the product of two tools: TAR (the tape archiver) and GZIP (the GNU-Zip). Tar has got the call option to automatically gzip/gunzip files after «taring».

tar -cvzf may_arch.tar.gz my_folder 
  • -c means «create»
  • -v means «verbose» (sometimes bothersome and slowing down. )
  • -z means «use (GNU)zip»
  • -f XYZ declares the name of the output file. (You should chose a helping name like XYZ.tar.gz)

There may also be .tar.bz2 endings. This is the product of the -j parameter instead of the -z parameter: you will choose compression with BZIP2 (-> man bzip2).

To extract you simply use -x (eXtract) instead of -c (Create):

You can use the zip and unzip command line utilities. These can be installed by running

sudo apt-get install zip unzip 

I know several ways, but since you’re new on linux. So I’ll tell you how to zip a file using GUI method (the easiest way).

enter image description here

  1. Create a new folder and fill it with anything you want, for example many of file (In my case, I’ll fill it with theme folder) :

enter image description here

  1. Right click the folder you want to zip and select «Compress. » option : enter image description here
  2. You can choose which file format you want by clicking combobox next to «Filename» textbox. Also you can set the folder you want to zip location. enter image description here

enter image description here

Clicking «Other options» will lead you to password section, in other word you can set password for your preferred file so someone (include you) have to enter password before unzip the file.

Источник

How to unzip all zipped files in a Linux directory?

Unzip is the Linux command utility that we will use to unzip all zipped files present in a Linux directory.

By default, the unzip utility is not present on most of the Linux distributions and we can install the same with the help of the commands mentioned below.

For Ubuntu and Debian

For CentOS and Fedora

Syntax

In the above syntax we just need to replace the file.zip with the file that we want to unzip.

Читайте также:  Просмотр операционной системы linux

Consider a case where I have a directory named direct1 that looks something like this −

immukul@192 direct1 % ls -ltr total 5216 -rwxrwxrwx 1 immukul staff 446966 Sep 23 1998 wget-1.5.3.tar.gz drwxr-xr-x 2 immukul staff 64 Jul 13 11:36 dr1 drwxr-xr-x 3 immukul staff 96 Jul 13 11:36 dr2 -rw-r--r-- 1 immukul staff 2201512 Jul 14 09:19 zipContent.zip -rw-r--r-- 1 immukul staff 122 Jul 14 16:10 somefile.txt drwxrwxrwx 5 immukul staff 160 Jul 16 10:01 d1 -rwxrwxrwx 1 immukul staff 300 Jul 16 10:06 sample.sh -rw-r--r-- 1 immukul staff 83 Jul 16 10:58 sample.txt drwxr-xr-x 3 immukul staff 96 Jul 16 11:05 dir1 drwxr-xr-x 3 immukul staff 96 Jul 16 11:46 dir2 -rw-r--r-- 1 immukul staff 661 Jul 16 11:47 newZip.zip

As one can notice, there are few .zip files present in the above directory and we can unzip all these .zip files with the help of the command shown below.

Command

Now once we run the following command, all the .zip files will be unzipped and their contents will be printed in the terminal.

Output

immukul@192 direct1 % ls -ltr total 13504 -rwxrwxrwx 1 immukul staff 446966 Sep 23 1998 wget-1.5.3.tar.gz -rwxrwxrwx 1 immukul staff 7 Jul 7 10:37 2.txt -rwxrwxrwx 1 immukul staff 4234901 Jul 7 17:41 file.txt -rwxrwxrwx 1 immukul staff 8 Jul 8 19:05 3.txt -rwxrwxrwx 1 immukul staff 946 Jul 12 18:45 sample.sh drwxr-xr-x 2 immukul staff 64 Jul 13 11:36 dr1 drwxr-xr-x 3 immukul staff 96 Jul 13 11:36 dr2 -rw-r--r-- 1 immukul staff 2201512 Jul 14 09:19 zipContent.zip -rw-r--r-- 1 immukul staff 122 Jul 14 16:10 somefile.txt -rw-r--r-- 1 immukul staff 83 Jul 16 10:58 sample.txt drwxr-xr-x 3 immukul staff 96 Jul 16 11:05 dir1 drwxr-xr-x 3 immukul staff 96 Jul 16 11:46 dir2 -rw-r--r-- 1 immukul staff 661 Jul 16 11:47 newZip.zip drwxrwxrwx 5 immukul staff 160 Jul 16 11:48 d1 drwxr-xr-x 4 immukul staff 128 Jul 16 11:48 d2

Источник

Practical Examples of the Unzip Command in Linux

Got a zip file in the terminal? Learn how to use the unzip command in Linux with these practical examples.

If you have a zip compressed file, you can unzip it in the Linux command line. The unzip command in Linux is quite versatile and you can use it do a lot more than just extracting zip file.

I have discussed how to gzip a folder in Linux in the past. It’s time to see various usage of the unzip command. Before you do that, make sure that unzip has been installed on your system. You can use your distribution’s package manager to install the command.

On Ubuntu and Debian, you can use this command:

Once you have verified that, let’s see how to use unzip in Linux terminal.

Unzip command in Linux

The unzip command has a really simple syntax:

If you use it to extract a zip file without any option, it will extract all the files in the current directory:

unzip webdesign.zip Archive: webdesign.zip inflating: 339252-PAJF05-394.ai inflating: 339252-PAJF07-322.eps inflating: 339252-PALBTI-224.ai inflating: 339252-PALBTL-394.eps inflating: 339252-PALBTM-53.jpg inflating: License free.txt inflating: License premium.txt

And that’s not what you would want most of the time. It’ll just flood your current directory with all the extracted files.

ls 339252-PAJF05-394.ai 339252-PALBTI-224.ai 339252-PALBTM-53.jpg 'License premium.txt' 339252-PAJF07-322.eps 339252-PALBTL-394.eps 'License free.txt' webdesign.zip

1. Unzip to a directory

The expected behavior is that you should have the files extracted to a certain directory, normally with the same name as the zip file.

You can specify the target directory where you want to extract the files.

unzip -d target_directory zip_file

If the target directory doesn’t exist, it will be created. You cannot create nested directories in this manner though.

Читайте также:  Linux сделать копию раздела

Do note that you can also put the target directory at the end but not all options can be added at the end.

unzip zip_file -d target_directory

2. See the content of the zip file without extracting

If you want to see what the zip file contains, you son’t always have to extract it first. You can use the -l option and it will show the content of the zip file.

As you can see, it also shows the timestamp of the files and the actual size of the individual files in bytes.

[email protected]:$ unzip -l webdesign.zip Archive: webdesign.zip Length Date Time Name --------- ---------- ----- ---- 205358 2018-06-18 23:14 339252-PAJF05-394.ai 996906 2018-06-18 23:14 339252-PAJF07-322.eps 213968 2018-06-20 00:00 339252-PALBTI-224.ai 1005362 2018-06-20 00:00 339252-PALBTL-394.eps 305531 2018-06-20 00:00 339252-PALBTM-53.jpg 1462 2018-06-20 09:45 License free.txt 1116 2018-06-20 09:45 License premium.txt --------- ------- 2729703 7 files

If you want, you can get more information like the compressed size, compression ratio by using the verbose mode with -v option. The CRC-32 in the output is the cyclic redundancy check.

[email protected]:$ unzip -v webdesign.zip Archive: webdesign.zip Length Method Size Cmpr Date Time CRC-32 Name -------- ------ ------- ---- ---------- ----- -------- ---- 205358 Defl:N 142097 31% 2018-06-18 23:14 792f2380 339252-PAJF05-394.ai 996906 Defl:N 221228 78% 2018-06-18 23:14 440390d3 339252-PAJF07-322.eps 213968 Defl:N 147568 31% 2018-06-20 00:00 cdb64dfc 339252-PALBTI-224.ai 1005362 Defl:N 226727 77% 2018-06-20 00:00 aed3d97a 339252-PALBTL-394.eps 305531 Defl:N 183363 40% 2018-06-20 00:00 e4ced90f 339252-PALBTM-53.jpg 1462 Defl:N 728 50% 2018-06-20 09:45 0eb9e17b License free.txt 1116 Defl:N 558 50% 2018-06-20 09:45 165dd84e License premium.txt -------- ------- --- ------- 2729703 922269 66% 7 files

3. Overwrite all the files without prompting

If there are already files with the same name in the directory where you are extracting the files, you’ll be promoted for each such files. You can force overwrite all the files with option -o .

unzip -o -d target_directory zip_file

4. Do not overwrite any files -n

If you don’t want any existing file to be overwritten by newly extracted files, use the -n option (stands for never overwrite).

unzip -n -d target_directory zip_file

5. Update files and create if necessary

This is slightly different the overwriting all the files. In this case, only those files will will be overwritten that have newer timestamp than the existing files. If a file doesn’t exist, it will be created.

You can achieve that with option -u:

unzip -u -d target_directory zip_file

6. Freshen existing files but create none

Slight change from the previous example here. In this one, it will update the existing files if they have older timestamp but it won’t create any new files even if they don’ exist.

The option -f allows you to do that:

unzip -f -d target_directory zip_file

7. Extract in quiet mode

When you unzip a file, it shows all the files that have been extracted on the display. Now imagine a zip file that has hundreds of files in it. If you extract it, your screen will be cluttered with the output.

You can use the quiet mode with option -q and you won’t see anything on the display:

unzip -q -d target_directory zip_file

8. Exclude files from extraction

You can also exclude certain files or certain type of files from being extracted.

unzip zip_file -x file_to_exclude

In my example, let’s say I don’t want to extract any .eps files.

[email protected]:$ unzip webdesign.zip -x *.eps Archive: webdesign.zip inflating: 339252-PAJF05-394.ai inflating: 339252-PALBTI-224.ai inflating: 339252-PALBTM-53.jpg inflating: License free.txt inflating: License premium.txt

Those were some of the most common examples of the unzip command in Linux. You can always check its man page to learn about more options.

Читайте также:  Dosbox on linux mint

Do you use some other option with unzip frequently? Why not share it with us in the comments?

Источник

Unzip all zip files in a target folder?

I have a curl cronjob which periodically downloads a bunch of zip files into a target folder. Like this:

curl www.zipdownloadfile.com/file.zip > file.zip 

Now I need to have Ubuntu unzip all of the zip files in that target folder. What’s the proper command which will unzip all of the files in a target destination/folder? Thanks

2 Answers 2

thats your command man this will unzip all zip file in a destination file

find /path-to-folder -name '*.zip' -exec unzip -d destination_folder <> + 

The issue here is that unzip *.zip doesn’t work for some reason. I guess the unzip doesn’t accept wildcard path arguments for files.

Nux’s answer is good but I use a slightly different version of the find command. If you cd into the folder you’ve downloaded all the zip files then you can just run:

find . -type f -name «*.zip» -exec unzip <> \;

This will search the current working directory and all sub-directories recursively with . , then find only files, -type f , then search for anything named *.zip with -name and it will execute unzip exec unzip and substitute the result of the search which is the full file name and place it with <> after the unzip command as the argument. \;` is just magical syntax to say ‘I’m done the command is finished.’.

This still worked for me in Ubuntu 16.04 to unzip all files in the current directory after downloading a huge number.

A similar command can also used to unrar a set of rar files you’ve downloaded simultaneously as well:

find . -type f -name «*.rar» -exec unrar x -e <> \;

The above magical command will search all files in the current directory and all folders and files recursively in sub-directories to find all files that end in .rar and then unrar them directly to the current working directory.

Let’s say you want to unpack a bunch of stuff that you’ve just recently downloaded:

Fri Nov 17 10:56 AM Downloads: tree . . ├── download1 │ ├── show01.r00 │ ├── show01.r01 │ ├── show01.r02 │ └── show01.rar ├── download2 │ ├── movie01.r00 │ ├── movie01.r01 │ ├── movie01.r02 │ ├── movie01.r03 │ └── movie01.rar └── download3 ├── program01.r00 ├── program01.r01 ├── program01.r02 ├── program01.r03 └── program01.rar 3 directories, 14 files 

This is only a small example you could have 20 or even 40 different foldedrs each containing their own master .zip file or .rar file that needs to be unrar’d. Doing a CD into each individual download directory to use ‘unrar’ is both time consuming and wasteful. Just use the find command!

sudo apt-get install unzip sudo apt-get install unrar cd ~/Downloads find . -type f -name "*.rar" -exec unrar x -e <> \; find . -type f -name "*.zip" -exec unzip <> \; 

Источник

Оцените статью
Adblock
detector