So, first, let’s create a tar bundle with multiple files in it: $ tar cvf sample.tar alma-linux-1.iso alma-linux-2.iso In such cases, first, we can create a tar bundle and then compress it using the gzip command. However, we can also observe that the gzip command doesn’t compress these files into a single file. In the previous two examples, we saw how to compress multiple files using a single command. The gzip command allows us to decompress the file using the -d option as shown. In the above example, the -r option traverses the directory in a recursive fashion. Now, let’s use the -r option to compress all the files from the dir-1 directory: $ gzip -r dir-1/ ![]() To understand this, first let us create a new directory and add a few files into it: $ mkdir dir-1 In a similar way, we can also compress all the files from a directory. In the previous example, we saw how to compress multiple files. Next, let’s compress the three files using the below command: $ gzip alma-linux-1.iso alma-linux-2.iso alma-linux-3.isoĬreate Multiple Gzip Files in Linux 7. So, first, let’s create multiple copies of the file using the following cp command: $ cp alma-linux.iso alma-linux-1.iso In a similar way, we can use the gzip command to compress multiple files at once. So far we saw how to compress a single file. Here, we can see that now the gzip command works in a non-interactive way. Now, let’s execute the same command with the -f option: $ gzip -f -k alma-linux.iso In such cases, we can use the -f option which overwrites the files forcefully. For example, if we are executing the gzip command from the script then the script will wait infinitely for the user input. However, this is not suitable every time. This interactive operation is safe and avoids overwriting files by mistake. Now, we can use the 'y' to overwrite the file or 'n' to abort the operation. Here, we can see that the gzip command waits for the user input. To understand this default behaviour, let’s execute the same command from the previous example: $ gzip -k alma-linux.iso Overwrite Gzip File Without Confirmationīy default, the gzip command works in an interactive way if the compressed file with the same name already exists. To understand this, let’s execute the following command: $ gzip -l uncompressed_name – it represents the name of the uncompressed file.ratio – it represents the compression ratio.uncompressed size – it represents the size of the uncompressed file in bytes.compressed size – it represents the size of the compressed file in bytes. ![]() In such a case, we can use the -l option to list the following fields: Sometimes, we want to display more details about the compressed file. In the above output, we can see that the zcat displays the contents of the compressed file without uncompressing it. To understand this, first, create a simple text file using the redirection operator: gz file, use the zcat command – which allows you to view the compressed file contents without uncompressing. In the above output, we can see that the original file is intact even after the compression. In such cases, we can use the -k option as shown. However, sometimes we want to keep the original file as well. However, if we observe carefully then we can notice that the gzip command deletes the original file after compressing it. In the previous example, we saw how easy it is to compress a file. We can also observe that, by default, the gzip command adds a. In the above output, we can see the new compressed file with the name. Now, let’s use the ls command to verify that the file has been compressed: $ ls -l To understand this, let’s use the following command to compress the ISO file: $ gzip alma-linux.iso To compress a single file, we just need to pass the file name to the gzip command. It is very common to see that, large ISO files or tar bundles are compressed to save disk space. ![]() One of the very common uses of the gzip command is to compress a large file. ![]() In the above syntax, the OPTIONS are used to alter the behavior of the command whereas the FILES represent the input files.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |