Zip Command with Examples
Zip command Syntax
zip [filename.zip] [file_to_zip]
Options
Options | Description | Syntax |
---|---|---|
-r | Recursively zip a directory | zip -r [filename.zip] [dir_name] |
-x | Explicitly exclude the specified files | zip -r . [filename.zip] -x [excluded_file] |
-m | Move the original files into the archive | zip -m [filename.zip] [file_to_zip] |
Examples
-
Zipping simple files
zip zip.zip hello.c world.c
-
Zipping a directory
zip -r zip.zip .
This command will zip the entire directory into the zip file.
-
Zipping a directory while excluding some subdirectories
zip -r zip.zip . -x "node_modules/*"
This command will exclude the subdirectory
node_modules
.zip -r zip.zip . -x \*.o
-
Zipping files and moving them into the archive
zip -m documents.zip *.txt
This command will zip all
.txt
files intodocuments.zip
and then delete the original.txt
files from the folder.
Browsing the zip file information
To browse the contents of a zip file using Vim or Neovim, you can simply open the zip file with either editor.
These editors have built-in support for browsing zip archives.
vim filename.zip
# or
nvim filename.zip
Upon opening the zip file in Vim or Neovim, you'll see a list of files contained in the archive.
You can navigate through this list to view the contents of individual files.
Remember that you're viewing the contents in a read-only mode – changes made here won't affect the actual files inside the zip archive.