32 C
Jaipur
Monday, October 26, 2020

Gzip and Keep Original File in Linux

Must read

Airtel Xstream App Is Now Available on Amazon Fire TV Stick: Report

Airtel Xstream came into existence more than a year ago. It was the company’s major play towards content aggregation, offering you a variety of...

GitHub Removes YouTube Download Tool in Response to DMCA Takedown Notice

Microsoft-owned GitHub has removed YouTube-dl, an incredibly popular Python library to help download YouTube videos. The move is in response to a Digital Millennium...

Wikiman: An Offline Search Engine For Arch Linux, Gentoo Wiki, And More

Official documentation of applications or commands is always the best way to learn about them if you want to know every detail, which a blog...

Gzip command by default delete the original file and replace it with a new compressed file with .gz extension. In this article, I am going to show you how to gzip file and keep the original ones intact.

Previously, we have seen how you can compress files using the zip command in a Linux system.  Additionally,  we have also seen how you can use the gzip command to compress and decompress files.

Gzip and keep the original file

We can use three options to keep the original file while using gzip:

Method 1: Using -k option

$ sudo gzip -k picture.img

or

$ sudo gzip --keep picture.img
gzip-k-keep-original

gzip keeping the original file

Method 2: Using -c option

$ sudo gzip -c picture.img > picture.img.gz

gzip c option to keep original file

For the gunzip command you can the same -c option to keep the original file.

Method 3: Using shell redirections

$ sudo gzip < picture.img > picture.img.gz

gzip shell redirection

Note: You might have noticed I have used sudo sh -c command, this is because redirection is done by shell and sudo don’t have permission

To gzip all files

To gzip all files in the current folder and subfolders, use:

$ sudo gzip -kr .

gzip all files

To gzip all files and subfolders

Unlike gzip command, tar command by default will keep the original directories or files, use:

$ sudo tar -zcvf compressednewfile1.tar.gz directorytocompress

or

$ sudo tar -zcvf allfilesdirectories.tar.gz *

Choose a selected number of directories to gzip:

$ sudo tar -zcvf directory1and2.tar.gz dir1 dir2

Conclusion

As you have seen in this guide, gzip allows you not only to compress a file but also gives you the privilege to retain the original file after compression. For users who prefer keeping the original files, this comes as a very handy method and saves you time and energy. We do hope that you found this helpful. Your feedback is much appreciated.

Source link

- Advertisement -

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

Airtel Xstream App Is Now Available on Amazon Fire TV Stick: Report

Airtel Xstream came into existence more than a year ago. It was the company’s major play towards content aggregation, offering you a variety of...

GitHub Removes YouTube Download Tool in Response to DMCA Takedown Notice

Microsoft-owned GitHub has removed YouTube-dl, an incredibly popular Python library to help download YouTube videos. The move is in response to a Digital Millennium...

Wikiman: An Offline Search Engine For Arch Linux, Gentoo Wiki, And More

Official documentation of applications or commands is always the best way to learn about them if you want to know every detail, which a blog...