Creating zip file on linux

How to zip a file in Ubuntu [closed]

Closed. This question is not about programming or software development. It is not currently accepting answers.

This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.

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?

I used information from this question and answer in a script, but I guess that’s not «programming» for some. The simple, perhaps «noob», questions are often the most useful and time saving on this website. Documentation is often marginal. The best way to learn and find answers fast is generally FAQ/Q&A. A community driven Q&A assists a lot of people where documentation fails. Should we make a new, competing website, if this is not welcomed here?

If you do this more than once, it might also be helpful to add -x «*.zip*» otherwise you inculde the «old» zipfile in your «new» zipfile

5 Answers 5

sudo apt-get install zip -y zip -r folder.zip folder 

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

In case you are just bundling fairly uncompressable stuff like jpg or mp3, you can opt for zero compression with -0 , i.e. zip -0 -r sample1.zip sample1/*

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 are some more related useful commands :

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

Regarding „some more useful“: creating a tar (‘tape archive’) and zip (aka creating the pkware zip file format format most popular under windows) are not at all the same thing.

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 
adding: first_file.txt adding: second_file.txt adding: third_file.txt 

To zip a folder in linux use below command

For Example ( if static is a folder name)

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)
Читайте также:  Linux как удалить загрузчик

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»)

# 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 
# 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 

Источник

How to Zip a File in Linux

ZIP is the most popular archive file format for compressing files and directories. Compressing files into an archived format helps conserve space and network bandwidth. Even though the tape archive (tar) format is more common on Linux systems, ZIP is also used often due to its popularity.

Linux offers the zip command for compressing files into ZIP format. Alternatively, creating ZIP files is possible through the GUI, too.

This guide shows how to zip files and directories through the command line and GUI in Linux.

How To Zip A File In Linux

Check if zip Is Installed

Not all Linux systems have the zip program installed by default. See whether the utility is available by checking the version:

zip --version terminal output

If the output prints the program version, continue to the following section. However, if the output shows the command is not found, install the zip and unzip utility with the following command:

sudo apt install zip unzip

Note: Installing unzip is not mandatory, but the command goes hand-in-hand with zip .

If you’re looking to unzip files, check out our guide on how to unzip a ZIP file.

Enter the sudo password and wait for the installation to complete.

Zip Files in Linux With the zip Command

The zip command helps create ZIP archive files. The general syntax for the zip command is:

Without any options, the command creates a new ZIP file. The additional options and syntax change the behavior and provide different functionalities.

zip Command Options

The zip command offers various work modes and options to help create ZIP files. The table below shows a short overview of the available options.

Tag Option or Mode Description
-u
—update
Mode Updates and adds new files. Creates a new archive if not found.
-f
—freshen
Mode Updates files without adding new ones. Creates a new archive if not found.
-d
—delete
Mode Chooses entries in an existing archive and removes them.
-U
—copy-entries
Mode Chooses entries from an existing archive and copies them into a new archive.
-e
—encrypt
Option Encrypts ZIP archive contents with a password. Starts a password entry prompt.
-i
—include
Option Includes only specified files.
-R
—recurse-patterns
Option Archives files recursively.
-sf
—show-files
Option Lists files the command would operate on, then exits.
-x
—exclude
Option Excludes specified files.
Option Regulates compression speed (0-9). Lower numbers are faster.

The zip command offers many other options you can view using the man command.

Create a ZIP Archive

The zip command, without any options, creates a new file. To test the command, do the following:

1. Create files for archiving:

The command creates five empty text files.

2. Use the zip command to archive the files:

zip files file1.txt file2.txt file3.txt file4.txt file5.txt

Create and zip files terminal output

The command outputs the actions taken and creates a files.zip archive.

List ZIP File Contents

The -sf option lists the contents of a ZIP file. Provide only the ZIP file name, for example:

zip -sf show files terminal output

The command lists the archive’s contents and exists.

Add Specific File Types to ZIP Archive

To add only specific file types to a ZIP file, use a wildcard and provide the filetype extension. For example:

zip all text files terminal output

The command adds all files with the .txt extension to the archive.

Add a Directory to ZIP Archive

Use the -r (recursive) option to add a directory to a ZIP file. For instance:

zip -r directory with files terminal output

The zip command adds the empty directory first, then populates it with the files.

Delete Files From ZIP Archive

1. To delete files from a ZIP archive, list the files from the archive using the -sf option first. For example:

2. Locate the file for deletion and run zip with the -d tag:

zip -d delete files terminal output

The command removes the specified files from the ZIP archive.

Create and Encrypt ZIP File

A password protects the ZIP archive from extraction. To add password encryption to a ZIP file, use the -e option:

zip -e encrypted file terminal output

The command starts a password entry prompt. After confirming, the files are added to the ZIP archive.

Control ZIP Compression Level

The zip command allows controlling the compression level. The ZIP file compression level and speed are reversely proportional. As the level increases, the compression takes longer.

To control the ZIP file compression level, use the following syntax:

zip files compression 5 terminal output

For the fastest compression, use -1 . For the highest level of compression, use -9 . Values between 1 and 9 provide in-between results (fast vs. level of compression).

Create a ZIP Archive Using The GUI

To create a ZIP file in Linux through the GUI, do the following:

1. Open Files and navigate to the appropriate directory.

2. Select the files for archiving, right-click the files, and choose Compress.

Ubuntu GUI Compress option

3. Enter the archive name and choose the .zip format from the dropdown menu.

Create archive ZIP GUI Ubuntu

4. Click Create to create the ZIP file.

The process creates a ZIP archive in the current location.

After reading this guide, you should know how to create a ZIP file in Linux with the zip command and GUI. For other file compression and archiving commands, check out the tar command.

Источник

How to Make a Zip File in Linux

This article was co-authored by wikiHow staff writer, Travis Boylls. Travis Boylls is a Technology Writer and Editor for wikiHow. Travis has experience writing technology-related articles, providing software customer service, and in graphic design. He specializes in Windows, macOS, Android, iOS, and Linux platforms. He studied graphic design at Pikes Peak Community College.

The wikiHow Tech Team also followed the article’s instructions and verified that they work.

This article has been viewed 79,817 times.

Zip files are one of the primary file types for archiving and compressing multiple files into one directory. All operating systems have the ability to make Zip files, and you can easily do this in Linux as well. This wikiHow article teaches you how to make and unzip a zip file in Linux/UNIX/Mac.

Using the Terminal

Image titled Make a Zip File in Linux Step 1

  • On most Linux distributions that have a graphical user interface, you can open the terminal by opening the Apps menu and clicking on the icon that resembles a black screen with a white text cursor.

Image titled Make a Zip File in Linux Step 2

  • Ubuntu and Debian: sudo apt install zip
  • CentOS and Fedora: sudo yum install zip .

Image titled Make a Zip File in Linux Step 3

  • For example, if the file you want to zip is in your «Documents» folder, you would type cd Documents and press Enter.

Image titled Make a Zip File in Linux Step 4

  • This command will not work if there is a space in the file name or folder you want to zip.
  • You can add as many files and folders to the end of the command as you want.
  • Add -r after «zip» in the command to include all subfolders in a folder to the zip file. For example zip -r zipfile.zip folder
  • Add -e after «zip» in the command to add a password to the zip file. You will then be asked to enter and verify a password.

Image titled Make a Zip File in Linux Step 5

Type unzip zip_file.zip and press ↵ Enter to unzip a file. Replace «zip_file.zip» with the actual name of the zip file. [2] X Research source

Using the Graphical User Interface

Image titled Make a Zip File in Linux Step 6

Open the Files app. Each distribution of Linux is a little bit different. These steps may be a little different on your Linux distribution but should be fairly similar. Click the icon that resembles a folder to open the Files app or whichever file browser app you are using.

Image titled Make a Zip File in Linux Step 7

Navigate to the file or folder that you want to zip. You can zip an entire folder or an individual file. Use the file browser to navigate to the file or folder you want to compress into a zip file.

Image titled Make a Zip File in Linux Step 8

Image titled Make a Zip File in Linux Step 9

Click Compress . It’s in the context menu. On some Linux distributions, this might say «Archive,» «Zip,» or something similar.

Image titled Make a Zip File in Linux Step 10

  • Some Linux distributions may use a default name instead of allowing you to enter a name for the file you are creating.

Image titled Make a Zip File in Linux Step 11

  • Alternatively, you can select «.tar.xz,» which is a compressed archive format used by LInux computers. You can also select «.7z,» which is a 7-zip file. 7-zip is an open-source version of Winzip.

Image titled Make a Zip File in Linux Step 12

Click Create . It’s either in the upper-right corner or lower-right corner of the dialogue box. On some distributions, this may say «Ok» or something similar. This creates a zip file of the file or folder.

Expert Q&A

Tips

If you zip up a file, change it, and then try to unzip it up, it will ask you if you want to replace the modified file with the file in the zip file.

You Might Also Like

Compile a Program in Linux

Install Google Chrome Using Terminal on Linux

Can Linux Run Exe

Can Linux Run .exe Files? How to Run Windows Software on Linux

Add or Change the Default Gateway in Linux

Open Ports in Linux Server Firewall

How to Open Linux Firewall Ports: Ubuntu, Debian, & More

Become Root in Linux

Take a Screenshot in Linux

Execute INSTALL.sh Files in Linux Using Terminal

How to Run an INSTALL.sh Script on Linux in 4 Easy Steps

Ping in Linux

Use Ping in Linux: Tutorial, Examples, & Interpreting Results

Boot Linux from a USB on Windows 10

Delete Read Only Files in Linux

How to Delete Read-Only Files in Linux

Use Wine on Linux

Run Files in Linux

Install Linux

How to Install Linux on Your Computer

Источник

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