Linux ha alcuni strumenti per comprimere file ed estrarre archivi. Puoi vederne alcuni elencati nelle tabelle seguenti. La prima tabella contiene i comandi di decompressione:
Decomprimi comando | Informazioni |
gzip -d file.php.gz gunzip file.php.gz | Estrai gli archivi creati con l'utility gzip. |
bzip2 -d file.php.bz2 bunzip2 file.php.bz2 | Estrai gli archivi creati con l'utility bzip2. |
decomprimi archivio.zip | Estrai gli archivi creati con l'utility zip. |
tar -zxvf filearchivio.tgz tar -jxvf filearchivio.tbz2 | Estrai gli archivi creati con tar + gzip/bzip2. -z per la decompressione gzip; -j per la decompressione bzip2 |
Per visualizzare le informazioni di sistema per ciascun comando, digita commandname --help
al terminale, come:
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 [~]#
Quindi, per estrarre un archivio .gz, usa gzip strumento:
root@web [/]# gzip -d archive_file.gz
o gunzip
root@web [/]# gunzip archive_file.gz
Ma come comprimi i tuoi file? Nella tabella seguente vedi alcuni comandi per comprimere file/directory:
Comprimi comandi | Informazioni |
file gzip1.htm | Comprimi il file usando gzip. |
bzip2 file1.htm | Comprimi il file usando bzip2. |
zip file1.zip file1.htm | Comprimere il file1.htm nell'archivio file1.zip. |
tar -zcvf files1.tgz file.htm tar -zcvf files1.tgz *.htm tar -zcvf files1.tgz /directory/dir1/ tar -jcvf files1.tbz2 file.htm tar -jcvf files1.tbz2 *.htm tar -jcvf files1.tbz2 /directory/dir1/ | Con l'utility tar puoi comprimere molti file. -z per la compressione gzip; -j per la compressione bzip2 |
Ad esempio, per comprimere una directory completa (con tutte le sottodirectory), utilizzare:
root@web [/]# tar -czvf archive.tar.gz /home/temp2/
Un altro tipo di archivio comune è RAR . È possibile scaricare il programma RAR da http://rarlabs.com/download.htm (per Linux 32/64 è disponibile solo una versione a riga di comando).
Come installarlo:
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
....