How to zip directory or files with ZIP command in LInux or any other Unix like OS?
Why would you want to ZIP files in Linux if you have already gzip and bzip archive algorithms? Well for historical reasons .ZIP is much supported across virtually all major operating systems like Unix, Linux, VMS, MSDOS, OS/2, Windows NT, Minix, Atari and Macintosh, FreeBSD, OpenBSD, NetBSD, Amiga and Acorn RISC and many other operating systems.
Assuming that zip command line tool is available across most GNU / Linux and WinZIP is available across almost all Windowses, the reason you might need to create .zip archive might be to just transfer the files from your Linux / FreeBSD desktop system or a friend with M$ Windows.
So below is how to archive recursively files inside a directory using zip command:
$ zip -r myvacationpics.zip /home/your-directory/your-files-pictures-text/
or you can write it shorter with omitting .zip as by default zip command would create .zip files
$ zip -r whatever-zip-file-name /home/your-directory/your-files-pictures-text/
The -r tells zip to recurse into directories (e.g. archive all files and directories inside your-files-pictures-text/)
If you need to archive just a files recursively with a file extension such as .txt inside current directory
$ zip -R my-zip-archive.zip '*.txt'
Above command would archive any .txt found inside your current directory if the zip command is for example issued from /home/hipo all found files such as /home/hipo/directory1, /home/hipo/directory2, /home/hipo/directory2/directory3/directory4 and all the contained subdirs that contain any .txt extension files will be added to the archive.
For the Linux desktop users that are lazy and want to zip files without much typing take a look at PeaZip for Linux 7Z / ZIP GUI interface tool
More helpful Articles
Tags: archive, command, directory, Files, linux?