So, the other day I needed to compress some files on a Linux system to make available to a customer. Most end users don’t know how to uncompress .tar, .gz, .bz2, etc formats on a Windows system. Even more so, Windows systems, since Windows XP has had the built in utility to uncompress .zip files, so sometimes you’ll need to know the simple, sometimes useful, zip
command in Linux.
The syntax of the command goes zip [switches] zipped-up-filename.zip [files or directory]
. The command is very simple, although, it took me a second to figure out to correct syntax to getting the command to zip up a folder recursively.
Zipping Up a File
[root@server]# zip zipped-up-filename.zip file1.txt |
Zipping Up More Than One File
[root@server]# zip zipped-up-filename.zip file1.txt file2.txt file3.log file4.inc |
Zipping Up A Subdirectory (and its subdirectories)
[root@server]# zip -r zipped-up-filename.zip folder-to-be-zipped/ |
Zipping Up the Current Directory (and its subdirectories)
This one’s similar, but a bit different, from the previous command:
[root@server]# zip -r zipped-up-filename.zip . |
Hope this helps with getting used to (hopefully you don’t get used to this command to much) the zip
command; comes in very useful when you least expect it.