There are available more commands to compress and decompress file in bash. Some of them are:
- tar
- zip / unzip
- rar / unrar
- gzip
- bzip2
Tar and untar
To create a tar.gz from bash shell you can use the following command:$ tar -zcvf myarchive.tar.gz mydirectory
$ tar -xvf myarchive.tar.gz
Zip and unzip
Create an archive form a text file:
Create an archive form a directory:
Create an archive with the subdirectories and files into a directory (without it):
Extraction of files and directories from an archive:
Extraction and overwrite the files and directories from an archive:
Extraction the files and directories from an archive to a target directory
$ zip myarchive.zip myfile.txt
$ zip -r myarchive.zip mydirectory
$ zip -r -D myarchive.zip mydirectory
$ unzip myarchive.zip
$ unzip -o myarchive.zip
$ unzip myarchive.zip -d mydirectory
Rar and unrar
Create a new rar archive myarchive.rar containing myfile.txt
$ rar a myarchive.rar myfile.txt
$ rar a myarchive.rar mydirectory/
$ rar a
-v10M -R myarchive.rar mydirectory/
$ unrar e myarchive.rar
$ unrar l myarchive.rar
Gzip
The command `gzip' is designed as a complement to `tar', not as a replacement. Instead the command`gunzip' can currently decompress files created by `gzip', `zip',
`compress' or `pack'. The detection of the input format is automatic.
Create an archive form a text file:$ gzip myfile.txt
$ gzip myfile.gz
Bzip2
Bzip2 compresses files using the Burrows-Wheeler block sorting text compression algorithm, and Huffman coding. The command-line options are deliberately very similar to those of GNU gzip, but they are not identical.
Create an archive form a text file:
$ bzip2 myfile.txt
Decompress the archive created in previous step:
$ bunzip2 myfile.txt.bz2
Internal Links
May be of interest to you:
No comments:
Post a Comment