Rate this article :
This article was useful to you ?
Yes
No
Vous avez noté 0 étoile(s)
Sommaire
Procédure
Compressing files via the terminal offers an effective method of managing storage space and facilitating data transfer. In this guide, we'll explore how to use tools such as gzip
, bzip2
, zip
, and tar
to compress and decompress files directly from a web terminal. We'll provide simple commands and examples to help you choose the right compression tool for your specific needs, from maximising compression to speed of operation.
Prior to this documentation, we invite you to access your hosting's Web Terminal.
The zip
command is a tool used for file compression. It is used to compress files and directories into .zip
archives, a format widely used for distributing and exchanging files because of its compatibility between different platforms.
Basic functions
zip
compresses files and directories, reducing their size and combining them into a single .zip
archive.zip
can simply group files into an archive without compression, using the -0
option (zero compression).Basic syntax
zip [options] archive_name.zip file1 file2 dir1 ...
Common options
-r
: Recursive, includes directories and their contents recursively.-q
: Silent mode, reduces command output for less clutter.-e
: Encrypts the archive, requiring the user to enter a password to secure the files.-u
: Updates the existing archive, adding only modified or new files.-m
: Moves files to the archive (removes them from their original location after adding them to the archive).Examples of use
Create an archive of several files:
zip archive.zip file1.txt file2.txt
This creates an archive archive.zip
containing file1.txt
and file2.txt
.
Archive a folder recursively:
zip -r archive.zip folder/
Archives the entire contents of the folder/
folder, including subfolders.
Encrypt an archive:
zip -e secure.zip file1.txt file2.txt
Creates an encrypted secure.zip
archive which will require a password to access its contents.
Update an existing archive:
zip -u archive.zip newfile.txt
Adds newfile.txt
to an existing archive archive.zip
, only if newfile.txt
is newer than the version in the archive or is not already there.Typical use
zip
is often used for software distribution, exchanging files between different platforms (such as between Windows and Unix), and for backups where files need to remain accessible without decompression.
In short, zip
is a versatile compression and archiving tool, ideal for reducing the size of files for storage or transfer, while ensuring compatibility between different operating systems.
The unzip
command is the complementary tool to zip
, used to extract and manage archives created with zip
. It decompresses files and directories stored in .zip
archives, making them accessible and usable again.
Basic functions
unzip
unzips .zip
archives, extracting their contents into the current directory or a specified directory.unzip
can be used to display the contents of an archive, allowing you to check its contents without extracting.Basic syntax
unzip [options] archive_name.zip
Common options
-l
: Lists the contents of the archive without extracting, displaying file names, size and date of last modification.-d
: Specifies the destination directory for extracting files.-o
: Overwrites existing files without asking for confirmation when extracting.-p
: Extracts files at standard output, often used to pass the contents to another command.-q
: Silent mode which reduces the amount of information displayed during extraction.Examples of use
Extract an archive into the current directory:
unzip archive.zip
This extracts all the files and directories contained in archive.zip
into the current directory.
List the contents of an archive:
unzip -l archive.zip
Displays the list of files in archive.zip
without extracting them.Extract an archive to a specific folder:
unzip archive.zip -d /path/to/destination
Extracts the contents of archive.zip
into the /path/to/destination
directory.Extract a specific file from the archive:
unzip archive.zip file1.txt
Extracts only file1.txt
from archive.zip
.Typical use
unzip
is often used to recover the contents of downloaded or received .zip
archives, for backup or data recovery tasks, and in scripts where archives need to be automatically decompressed for software installation or file updates.
In short, unzip
is an essential tool for manipulating .zip
archives, allowing users to easily extract, manage and use archived content.
The tar
command (short for "tape archive") is a file management tool. It is mainly used to create file archives and to extract files from archives. Although traditionally associated with magnetic tape, tar
is widely used for archiving files on hard disks and other storage media.
Basic functions
tar
can be used to combine numerous files into a single archive file, making them easier to store and transfer.Basic syntax
tar [options] [archive-file] [file or directory to be archived]
Common options
-c
: Creates a new archive.-x
: Extracts files from an archive.-v
: Verbose mode which displays details of operations performed.-f
: Used to specify the filename of the archive. This option is always necessary as tar
has no default filename.-z
: Uses gzip to compress or decompress the archive (creates or extracts .tar.gz
or .tgz
files).-j
: Uses bzip2 to compress or decompress (creates or extracts .tar.bz2
files).J
: Uses xz for compression or decompression (creates or extracts .tar.xz
files).Examples of use
Create a tar archive of several:
tar -cvf archive.tar file1 file2
This creates an archive named archive.tar
containing file1
and file2
.
Create a compressed tar.gz archive:
tar -czvf archive.tar.gz directory/
Archives and compresses the contents of the directory/
directory using gzip.Extract the contents of a tar archive:
tar -xvf archive.tar
Extract all files from archive.tar
into the current directory.List the contents of a tar archive without extracting:
tar -tvf archive.tar
Displays a list of files contained in archive.tar
.Usage tips
-v
option to view the archiving or extraction process, which can be useful for debugging.tar
is therefore an indispensable command for managing files and archives, offering considerable flexibility in the way you manipulate, compress and decompress archives.
The gzip
command (GNU zip) is a very popular compression utility. It is mainly used to compress files, reducing their size to save disk space and speed up data transfer. gzip
is often used in combination with other tools, such as tar
, to compress entire directories.
Basic functions
gzip
replaces each file with a compressed version of itself, bearing the .gz
extension.Basic syntax
gzip [options] [file...]
gzip
.Common options
-d
: Decompresses files (equivalent to the gunzip
command).-k
: Keeps the source files, i.e. gzip
will not delete the original files after compressing them.-c
: Writes to standard output, allowing redirection to another file or program.-r
: If the arguments include directories, gzip
will go through them recursively, compressing all the files they contain.-v
: Verbose mode, displays the size of files before and after compression as well as the compression ratio.-9
: Specifies the compression level, with 9
representing the highest and slowest compression level. The default level is -6
.Examples of use
Compressing a:
gzip example.txt
This will replace example.txt
with example.txt.gz
in the current directory.
Unzip a file:
gzip -d example.txt.gz
Or, equivalently :
gunzip example.txt.gz
This will reconstitute the original example.txt
file from example.txt.gz
.
Compress several files:
gzip file1.txt file2.txt file3.txt
Each file will be compressed and replaced by a corresponding .gz
version.
Compress and redirect the output:
gzip -c file.txt > file.txt.gz
Compresses file.txt
and redirects the compressed output to file.txt.gz
without deleting the original file.
Typical use
gzip
is ideal for compressing individual files or data streams. For archives of multiple files or directories, gzip
is often used with tar
, as in
tar czf archive.tar.gz directory/
which creates a compressed tar archive of directory
.
In summary, gzip
is a simple and effective file compression tool, widely used to reduce the size of files for storage or transmission.
You now know how to :
gzip
, bzip2
, zip
and tar
commands to optimise your storage space and secure the transfer of your data 💾.zip
command and manage them efficiently using the many options available 🗄️.unzip
command, with the option of viewing the contents without decompression 📂.tar
command, creating compact archives or extracting their contents 📦.gzip
to save space and make it easier to share compressed .gz files 🚀.Mastering these compression tools is essential in the day-to-day management of files and directories, whether for backup, archiving or transfer purposes. Each command offers unique benefits and can be used individually or in combination to best meet your requirements.
We hope you have found this article useful and that it has given you the knowledge you need to optimise your use of storage space and the management of your files. We thank you for reading this and invite you to share your experiences or ask any questions you may have by leaving a comment below. Your feedback is invaluable and helps us to continue improving our services. Thank you and see you soon on our platform! 😊👍
Rate this article :
This article was useful to you ?
Yes
No
1mn reading
How do I connect to the Web Terminal with LWS Panel? (ssh web console)
4mn reading
How can I use GIT with the Web terminal on my LWS shared hosting?
2mn reading
How to change the PHP version of the LWS Panel Web Terminal
0mn reading
What can I do on my WordPress site using the Web Terminal?