Using zip and zipcloak commands on Linux

Both the Linux zip and zipcloak commands can create encrypted zip files, but they have some important and interesting differences. Here’s what you need to know about how they work and what you should know when using them.

compression

The zip command provides an easy way to take a set of files and compress their contents into a smaller file. To combine a set of files into a single file (usually this is done to make it easier to copy them to other systems), use the command shown below. The first parameter is the name for the zip file, followed by a list of files to include.

$ zip file.zip file1 file2
Added: file1 (58% smaller)
Added: file2 (60% smaller)

The following command provides a simple example where files are added to an encrypted zip file. Note that the -e option specifies that the generated zip file will be encrypted. If you do not enter the same password each time you are prompted, the command will fail.

$ zip -e files.zip File 1 File 2 Enter password: Verify password:
Added: file1 (58% smaller)
Added: file2 (60% smaller)

The zip command not only stores files together but also reduces their size during processing. The zip file in these examples is less than half the size of the two files combined. Note the “shrink” line in the output shown above.

-rw-r—r—. 1 shs shs 2224 November 19, 14:18 File 1

-rw-r—r—. 1 shs shs 6712 November 19, 14:18 File 2

-rw-r—r—. 1 shs shs 3993 November 19, 14:19 files.zip

The original files can be deleted later after being added to the encrypted zip file, but you will need to retain the password used to extract the contents later.

You can also use the zip command to recursively collect files and include them in a single zip file. Here is an example command that will place all the files in the bin directory into a file named “bin.zip”.

$ zip -r bin.zip ~/bin

Although the zip command can create encrypted files, it cannot encrypt existing zip files. To do this, you can use the zipcloak command or go through the process of extracting the contents of the zip files and then recompressing them using the -e option to put them back in encrypted form.

Note: Whether encrypted or not, a Zip file is smaller than the collection of individual files it contains.

zipper poncho

The zipcloak command differs from zip in one very important way: it will encrypt or decrypt an existing zip file, but it will not create the zip file itself. To encrypt zip files using zipcloak command, use the command as shown below.

$ zipcloak file.zip

enter password:

verify password:

Encryption: File 1

Encryption: File 2

$ ls -l file.zip

-rw-r—r—. 1 shs shs 3961 November 19, 14:30 files.zip

After encryption, the resulting file is almost the same size as the file created without encryption. In this case, it’s just a little smaller.

unzip

The unzip command will extract the contents of zip files regardless of whether they are encrypted or not. However, it will ask for the password for the encrypted file.

$ Unzip files.zip

Archive: files.zip

[efiles.zip] file1 password:

Inflatable: File 1

Inflatable: File 2

If files with the same name exist in the directory, you will be asked if you want to overwrite them. Additionally, if you don’t want to extract all files, you can select individual files from the zip file. Here’s an example of extracting a single file and choosing to overwrite the current file:

$ Unzip file.zip file 2

Archive: files.zip

[efiles.zip] file2 password:

Replace file 2? [y]es, [n]o, [A]ll, [N]one, [r]ename: y

Inflatable: File 2

compatibility

The zip and zipcloak commands are correctly compatible. The unzip command can extract content from both unencrypted and encrypted zip files and works as expected regardless of whether the file was encrypted using the zip -e (encrypt) command or the zipcloak command. Similarly, the zipcloak -d (decrypt) command will decrypt an encrypted zip file, regardless of whether it was encrypted using the zip -e command or the zipcloak command.

wrap up

Zip files are often used to locally back up a group of files that may be changing, or to copy a group of files at a time to another system. The zip and unzip commands allow you to easily create zip files or extract content from them. The zipcloak command allows you to encrypt zip files or extract from encrypted zip files.

X

Por favor, activa JavaScript en tu navegador para completar este formulario.
Introduzca los detalles del producto, como la configuración de la interfaz, el entorno, etc., y otros requisitos específicos para recibir un presupuesto preciso.

es_ESSpanish
Por favor, activa JavaScript en tu navegador para completar este formulario.
Introduzca los detalles del producto, como la configuración de la interfaz, el entorno, etc., y otros requisitos específicos para recibir un presupuesto preciso.