How to zip a file in Ubuntu

I use Ubuntu. When I have to zip a folder I use the command zip folder.zip folder/

The result is an empty zipped folder! Where did all the files in the folder go?

6

4 Answers

Try zip -r folder.zip folder.

The -r flag will tell it to be recursive, which may be needed for a directory.

2

If zip command is not working then you need to install zip first. Here is the command which will install zip, gzip and tar.

sudo apt-get install zip gzip tar 

then you can zip, gzip or tar. zip the folder :

zip -r myzipped.zip my_folder 

Here -r means recurrsive.

Here are some more related useful commands :

unzip myzipped.zip tar -cvzf my.tar.gz directory_name tar -xvzf myzipped.tar.gz 
1

check out solution below: You can create a simple zip file with zip command without using any options.

For example to create a zip file of text files first_file.txt, second_file.txt and third_file.txt run below command:

sudo zip newfile.zip first_file.txt second_file.txt third_file.txt 

The output should be:

adding: first_file.txt adding: second_file.txt adding: third_file.txt 

for more information visit

1

Let's take the question "How to zip a file in ubuntu" as "how to compress a file in Ubuntu".

Please note that you have the following trade-offs:

  • Speed at compression time
  • Speed at decompression time
  • Size of archive
  • Additional features (e.g. adding a password)

Also, you can distinguish creating an archive (multiple files in one file) and compressing it. If you see it as a two-step process ((1) Archive (2) compress) you can solve them independently.

Please also note that different compression algorithms shine in different scenarios. There is no single algorithm that is always best ("no free lunch")

zip

# A file zip your_big_file # Archive a directory + compress it zip -r compressed.zip your_big_directory 

gzip

# -9: Use strongest (and slowest) compression gzip -9 your_big_file 

tar

# Archive a directory + compress it # c, --create : Create a new archive. # -z, --gzip, --gunzip: filter the archive through gzip # -j, --bzip2 : filter the archive through bzip2 # -f, --file=ARCHIVE : Use archive file (or device) ARCHIVE. tar cvzf compressed.tar.gz your_big_directory/ 

bzip2

# -9: Use strongest (and slowest) compression bzip -9 your_big_file 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like