Linux 101: How to create a compressed archive of a folder from the CLI with zip

Find out how easy it is to create compressed archives from the Linux command line, using zip. Jack Wallen shows you how.

Image: Jack Wallen

Recently I showed you how to create compressed archives from Linux command line using the tar order. This time I want to demonstrate the same task, but using a tool that you probably already know. The tool in question is zip, and it creates compressed zip files from whatever you throw at it.

SEE: 5 Linux Server Distributions You Should Be Using (TechRepublic Premium)

So let’s say you have the TEST folder and you want to create the compressed file so you can send it to a coworker. Fortunately, Linux can use the zip tool, but first you may need to install it with a command like sudo apt-get install zip -y Where sudo dnf install zip -y.

Once installed, zip is ready to go. Let’s compress this TEST folder. The way you create the compressed file is not as easy as you might think. The basic command is zip NAME (where NAME is the name of the folder to compress). However, if you just ran the command zip TEST, you would end up with a file named, but after unzipping it you would find that the contents are missing.

Why? Because you only compressed the folder, not the contents.

To include the contents of the TEST folder, you would add the recursive flag, as in zip -r TEST.

SEE: Rust: What Developers Need To Know About This Programming Language (Free PDF) (TechRepublic)

When you run the command with the -r flag, you will see that zip appends each file in the directory to the compressed file. This time, if you unzip the file, with the command unzip, the contents of the directory remain intact.

And that’s all there is to creating compressed archives from Linux command line interface, using zip tool.

Subscribe to TechRepublic How to make technology work on YouTube for all the latest technical advice for professionals at Jack Wallen’s business.

Also look

Comments are closed.