Posts

Zip Command with Examples

Zip command Syntax

zip [filename.zip] [file_to_zip]

Options

OptionsDescriptionSyntax
-rRecursively zip a directoryzip -r [filename.zip] [dir_name]
-xExplicitly exclude the specified fileszip -r . [filename.zip] -x [excluded_file]
-mMove the original files into the archivezip -m [filename.zip] [file_to_zip]

Examples

  1. Zipping simple files

    zip zip.zip hello.c world.c
    
  2. Zipping a directory

    zip -r zip.zip .
    

    This command will zip the entire directory into the zip file.

  3. 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
    
  4. Zipping files and moving them into the archive

    zip -m documents.zip *.txt
    

    This command will zip all .txt files into documents.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.