Learn how to use gzip on a directory and subdirectories. Our Server Management Support team is here to help you with your questions and concerns.
How to use gzip on a directory and subdirectories
Gzip is a popular file compression utility. It helps reduce the size of files and directories by compressing them into a single `.gz` file.
Our experts would like to point out that gzip works for individual files, not directories. To compress entire directories, our experts recommend tar or combining the two.
How to compress a folder with gzip
To compress a directory and its subdirectories, we can combine the tar and gzip commands as seen here:
Tar -z
This allows us to create compressed archives easily.
Now, let’s take a look at the syntax of this command:
tar -zcvf [result-filename.tar.gz] [path-of-directory-to-compress]
Where:
- -z: It compresses the file or directory with gzip.
- -c: It creates a new archive.
- -v: It displays progress while creating the archive.
- -f: It specifies the desired filename or directory to compress.
For example, if we want to compress a folder called “customerdetails”, we can run this command:
tar -zcvf customerdetails_compressed.tar.gz customerdetails
When we run this command with the `-v` option, we will be able to see a list of filenames as they are added to the archive. This gives us a closer look at the compression progress.
How to Extract Compressed Files
Once we compress our directory with gzip, we can extract the contents. This is done with this command:
tar -xvzf [our-tar-file.tar.gz]
Where:
- -z: It decompresses the file or directory with gzip.
- -x: It extracts files from the archive. It also extracts specific files if mentioned.
- -v: It displays progress while extracting.
- -f: It specifies the input `.tar.gz` file.
How to extract content to a custom directory
Furthermore, we can extract the contents to a custom directory by using the `-C` or `–directory` option in our extraction command.
For example:
tar -xvzf sandbox_compressed.tar.gz -C /target/directory
Here, the contents will be extracted to `/target/directory`.
[Need assistance with a different issue? Our team is available 24/7.]
Conclusion
In brief, our Support Experts demonstrated how to use gzip on a directory and subdirectories.
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
0 Comments