Find out how easy it is to create compressed archives from the Linux command line, using zip. Jack Wallen shows you how.
Recently, I showed you how to create compressed archives from the Linux command-line using the tar command. This time I want to demonstrate the same task, but using a tool you're probably already familiar with. 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 folder TEST and you want to create the compressed file TEST.zip so you can send it to a colleague. Fortunately, Linux can use the zip tool, but first, you might have to install it with a command like sudo apt-get install zip -y or sudo dnf install zip -y.
Once installed, zip is ready to go. Let's compress that TEST folder. How you create the zipped file isn't quite as simple as you might think. The basic command is zip NAME.zip NAME (where NAME is the name of the folder to be compressed). However, if you simply issued the command zip TEST.zip TEST, you'd wind up with a file named TEST.zip, but after uncompressing it, you'd find it's missing the contents.
Why? Because you only compressed the folder, not the contents.
To include the contents of the TEST folder, you'd add the recursive flag, as in zip -r TEST.zip TEST.
SEE: Rust: What developers need to know about this programming language (free PDF) (TechRepublic)
When you issue the command with the -r flag, you'll see zip adds every file within the directory to the compressed file. This time, if you decompress the file, with the command unzip TEST.zip, the contents of the directory remain intact.
And that's all there is to creating compressed archives from the Linux Command Line Interface, using the zip tool.
Subscribe to TechRepublic's How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.
- Programming languages: Objective-C slides down the popularity rankings (TechRepublic)
- Codecademy partners with Black and Brilliant for 10-week AI course (TechRepublic)
- How to become a developer: A cheat sheet (TechRepublic)
- Kubernetes: A cheat sheet (free PDF) (TechRepublic)
- Microsoft Linux is not what you thought (or hoped) it would be (TechRepublic)
- A guide to The Open Source Index and GitHub projects checklist (TechRepublic Premium)
- Linux, Android, and more open source tech coverage (TechRepublic on Flipboard)