Linux dispose de quelques outils pour compresser des fichiers et extraire des archives. Vous pouvez voir certains d'entre eux répertoriés dans les tableaux ci-dessous. Le premier tableau contient les commandes de décompression :
Commande de décompression | Informations |
gzip -d fichier.php.gz fichier gunzip.php.gz | Extraire les archives créées avec l'utilitaire gzip. |
bzip2 -d fichier.php.bz2 bunzip2 fichier.php.bz2 | Extraire les archives créées avec l'utilitaire bzip2. |
décompressez archive.zip | Extraire les archives créées avec l'utilitaire zip. |
tar -zxvf fichierarchive.tgz tar -jxvf archivefile.tbz2 | Extraire les archives créées avec tar + gzip/bzip2. -z pour la décompression gzip ; -j pour la décompression bzip2 |
Pour voir les informations système pour chaque commande, tapez commandname --help
au terminal, comme :
root@web [~]# gzip --help
Usage: gzip [OPTION]... [FILE]...
Compress or uncompress FILEs (by default, compress FILES in-place).
Mandatory arguments to long options are mandatory for short options too.
-c, --stdout write on standard output, keep original files unchanged
-d, --decompress decompress
-f, --force force overwrite of output file and compress links
-h, --help give this help
-l, --list list compressed file contents
-L, --license display software license
-n, --no-name do not save or restore the original name and time stamp
-N, --name save or restore the original name and time stamp
-q, --quiet suppress all warnings
-r, --recursive operate recursively on directories
-S, --suffix=SUF use suffix SUF on compressed files
-t, --test test compressed file integrity
-v, --verbose verbose mode
-V, --version display version number
-1, --fast compress faster
-9, --best compress better
--rsyncable Make rsync-friendly archive
With no FILE, or when FILE is -, read standard input.
Report bugs to <[email protected]>.
root@web [~]#
Donc, pour extraire une archive .gz, utilisez le gzip outil :
root@web [/]# gzip -d archive_file.gz
ou gunzip
root@web [/]# gunzip archive_file.gz
Mais comment compressez-vous vos fichiers ? Dans le tableau ci-dessous, voyez quelques commandes pour compresser des fichiers/répertoires :
Compresser les commandes | Informations |
fichier gzip1.htm | Compressez le fichier à l'aide de gzip. |
bzip2 fichier1.htm | Compressez le fichier à l'aide de bzip2. |
fichier zip1.fichier zip1.htm | Compressez le fichier1.htm dans l'archive file1.zip. |
tar -zcvf fichiers1.tgz fichier.htm tar -zcvf fichiers1.tgz *.htm tar -zcvf fichiers1.tgz /répertoire/dir1/ tar -jcvf fichiers1.tbz2 fichier.htm tar -jcvf files1.tbz2 *.htm tar -jcvf files1.tbz2 /répertoire/dir1/ | Avec l'utilitaire tar, vous pouvez compresser de nombreux fichiers. -z pour la compression gzip ; -j pour la compression bzip2 |
Par exemple, pour compresser un répertoire complet (avec tous les sous-répertoires), utilisez :
root@web [/]# tar -czvf archive.tar.gz /home/temp2/
Un autre type d'archive courant est RAR . Vous pouvez télécharger le programme RAR à partir de http://rarlabs.com/download.htm (pour Linux 32/64, seule une version en ligne de commande est disponible).
Comment l'installer :
root@web [/temp2]# wget http://rarlabs.com/rar/rarlinux-x64-5.5.b3.tar.gz
--2017-05-26 14:54:47-- http://rarlabs.com/rar/rarlinux-x64-5.5.b3.tar.gz
Resolving rarlabs.com (rarlabs.com)... 5.135.104.98
Connecting to rarlabs.com (rarlabs.com)|5.135.104.98|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 534195 (522K) [application/x-gzip]
Saving to: 'rarlinux-x64-5.5.b3.tar.gz'
100%[========================================================================================================
2017-05-26 14:54:48 (845 KB/s) - 'rarlinux-x64-5.5.b3.tar.gz' saved [534195/534195]
root@web [/temp2]# tar -zxvf rarlinux-x64-5.5.b3.tar.gz
rar/
rar/order.htm
rar/acknow.txt
rar/readme.txt
rar/default.sfx
rar/license.txt
rar/rarfiles.lst
rar/whatsnew.txt
rar/makefile
rar/rar
rar/unrar
rar/rar.txt
root@web [/temp2]# cd rar
root@web [/temp2/rar]# install rar unrar
root@web [/temp2/rar]# rar -?
RAR 5.50 beta 3 Copyright (c) 1993-2017 Alexander Roshal 23 May 2017
Trial version Type 'rar -?' for help
Usage: rar <command></command> - -
<@listfiles...> <path_to_extract\>
a Add files to archive
c Add archive comment
ch Change archive parameters
cw Write archive comment to file
d Delete files from archive
e Extract files without archived paths
f Freshen files in archive
i[par]= Find string in archives
k Lock archive
l[t[a],b] List archive contents [technical[all], bare]
m[f] Move to archive [files only]
p Print file to stdout
r Repair archive
rc Reconstruct missing volumes
rn Rename archived files
rr[N] Add data recovery record
rv[N] Create recovery volumes
s[name|-] Convert archive to or from SFX
t Test archive files
u Update files in archive
v[t[a],b] Verbosely list archive contents [technical[all],bare]
x Extract files with full path
....