How to ZIP and UNZIP files in Linux?

LearnTips LearnTips How to ZIP and UNZIP files in Linux?

Tagged: 

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #3861

    ZIP is the most commonly used archive file format that supports lossless data compression. A .zip file is a data container that contains one or more compressed files or directories. Let’s learn how to ZIP (compress) and UNZIP (decompress) files in Linux using the zip command.

    How to install ZIP UNZIP in Linux?

    To ZIP and UNZIP files in Linux, we need to install ZIP UNZIP first.

    On Debian and Ubuntu, you can use the following command.

    sudo apt-get install zip unzip

    On CentOS and Fedora, you can use the following command.

    sudo yum install zip unzip

    How to ZIP files and directories in Linux?

    To ZIP one or more files, you need to use the zip command followed by name of the archive that you want to create followed by names of files that you want to add to the archive, all separated by a space as shown below.

    zip archivename.zip filename1 filename2 filename3

    To ZIP one or more directories, you need to use the zip command with the -r option followed by name of the archive that you want to create followed by names of files that you want to add to the archive, all separated by a space.

    zip -r archivename.zip directoryname1 directoryname2 directoryname3

    The -r option traverses the whole directory structure recursively.

    You can also add multiple files and directories to the same archive as shown below.

    zip -r archivename.zip filename1 filename2 directoryname1 directoryname2

    How to UNZIP files in Linux?

    To UNZIP files, you need to use the unzip command followed by the name of the archive that you want to UNZIP, separated by a space.

    unzip archivename.zip

    If you want to UNZIP just a single file from an archive, you can use the unzip command followed by the archive name and the file name, all separated by a space.

    unzip archivename.zip filename1

    If you want to UNZIP files to a specific directory, then you use the unzip command as shown below.

    unzip archivename.zip -d ./directoryname/

    Learn more Linux commands.

Viewing 1 post (of 1 total)