2.11.16. Creating, viewing, testing and unpacking an archive
Archiving
zip
Adding files and directories to the archive:
zip -r archive.zip file1.txt file2.txt directory1 directory2
In a team:
-r
— archive the contents of the specified directories.archive.zip
— the name of the target archive. If the archive does not exist, it will be created.file1.txt
and so on — the files to be archived.directory1
and so on — the directories to be archived.
7z
Adding files and directories to the archive:
7za a archive.7z file1.txt file2.txt directory1 directory2
In a team:
a
— add files and directories to the archive.archive.7z
— the name of the target archive. If the archive does not exist, it will be created.file1.txt
and so on — the files to be archived.directory1
and so on — the directories to be archived.
tar
Attention!
tar is an uncompressed format. Archiving does not reduce the size of the files, but simply merges them into one.Archiving files and directories:
tar -cvf archive.tar file1.txt file2.txt directory1 directory2
In a team:
-c
- create a new archive.-v
— display information during archiving.-f
- means that the next argument in the command is the name of the archive.archive.tar
— the name of the target archive. If the archive already exists, if the key is present-c
it will be overwritten.file1.txt
and so on — the files to be archived.directory1
and so on — the directories to be archived.
Adding files and directories to the archive:
tar -rvf archive.tar file1.txt file2.txt directory1 directory2
In a team:
-r
- add files and directories to the archive.-v
— display information during archiving.-f
- means that the next argument in the command is the name of the archive.archive.tar
— the name of the target archive. If the archive does not exist, it will be created.file1.txt
and so on — the files to be archived.directory1
and so on — the directories to be archived.
tar.gz
Notes:
- gzip compresses worse than bzip2, but is faster.
- The archive file can have extensions
tar.gz
,tar.gzip
ortgz
.
Archiving files and directories:
tar -czvf archive.tar.gz file1.txt file2.txt directory1 directory2
In a team:
-c
- create a new archive.-z
— compress data using gzip.-v
— display information during archiving.-f
- means that the next argument in the command is the name of the archive.archive.tar
— the name of the target archive. If the archive already exists, if the key is present-c
it will be overwritten.file1.txt
and so on — the files to be archived.directory1
and so on — the directories to be archived.
tar.bz2
Notes:
- bzip2 compresses better than gzip, but is slower.
- The archive file can have extensions
tar.bz2
,tar.bzip2
,tbz2
,tb2
ortbz
.
Archiving files and directories:
tar -cjvf archive.tar.bz2 file1.txt file2.txt directory1 directory2
In a team:
-c
- create a new archive.-j
— compress data using bzip2.-v
— display information during archiving.-f
- means that the next argument in the command is the name of the archive.archive.tar
— the name of the target archive. If the archive already exists, if the key is present-c
it will be overwritten.file1.txt
and so on — the files to be archived.directory1
and so on — the directories to be archived.
View content
Universal way
Viewing the contents of the archive:
lsar archive.7z
In a team:
archive.7z
— the name of the archive.
zip
Viewing the contents of the archive:
unzip -l archive.zip
In a team:
-l
— display a list of files in the archive.archive.zip
— the name of the archive.
7z
Viewing the contents of the archive:
7za l archive.7z
In a team:
l
— display a list of files in the archive.archive.7z
— the name of the archive.
rar
Viewing the contents of the archive:
unrar l archive.rar
In a team:
l
— display a list of files in the archive.archive.rar
— the name of the archive.
tar
Viewing a summary of the contents of the archive:
tar -tf archive.tar
In a team:
-l
— display a list of files in the archive.-f
- means that the next argument in the command is the name of the archive.archive.tar
— the name of the archive.
View the full contents of the archive:
tar -tvf archive.tar
In a team:
-l
— display a list of files in the archive.-v
— display detailed information.-f
- means that the next argument in the command is the name of the archive.archive.tar
— the name of the archive.
tar.gz
tar.gz
, tar.gzip
or tgz
.
Viewing a summary of the contents of the archive:
tar -tf archive.tar.gz
In a team:
-l
— display a list of files in the archive.-f
- means that the next argument in the command is the name of the archive.archive.tar.gz
— the name of the archive.
View the full contents of the archive:
tar -tvf archive.tar.gz
In a team:
-l
— display a list of files in the archive.-v
— display detailed information.-f
- means that the next argument in the command is the name of the archive.archive.tar.gz
— the name of the archive.
tar.bz2
tar.bz2
, tar.bzip2
, tbz2
, tb2
or tbz
.
Viewing a summary of the contents of the archive:
tar -tf archive.tar.bz2
In a team:
-l
— display a list of files in the archive.-f
- means that the next argument in the command is the name of the archive.archive.tar.bz2
— the name of the archive.
View the full contents of the archive:
tar -tvf archive.tar.bz2
In a team:
-l
— display a list of files in the archive.-v
— display detailed information.-f
- means that the next argument in the command is the name of the archive.archive.tar.bz2
— the name of the archive.
Testing
zip
Archive testing:
unzip -tq archive.zip
In a team:
-t
— test the archive for errors.-q
- display a minimum of information.archive.zip
— the name of the archive.
7z
Archive testing:
7za t archive.7z
In a team:
t
— test the archive for errors.archive.7z
— the name of the archive.
rar
Archive testing:
unrar t archive.rar
In a team:
t
— test the archive for errors.archive.rar
- the name of the archive.
tar.gz
tar.gz
, tar.gzip
or tgz
.
Archive testing:
gzip -t archive.tar.gz
In a team:
-t
— test the archive for errors.archive.tar.gz
— the name of the archive.
tar.bz2
tar.bz2
, tar.bzip2
, tbz2
, tb2
or tbz
.
Archive testing:
bzip2 -t archive.tar.bz2
In a team:
-t
— test the archive for errors.archive.tar.bz2
— the name of the archive.
gz
Archive testing:
gzip -tv archive.gz
In a team:
-t
— test the archive for errors.-v
— display the test result.archive.gz
— the name of the archive.
Unpacking
Universal way
Unpacking the contents of the archive into the current directory:
unar archive.7z
In a team:
archive.7z
- the name of the archive.
Unpacking the contents of the archive into the specified directory:
unar archive.7z -o /path/to/dir
In a team:
archive.7z
- the name of the archive.-o
— unpack to the specified directory./path/to/dir
- path to the specified directory.
zip
Attention!
To avoid possible problems with encoding, unpack archives containing files with Cyrillic names using unar.Unpacking the contents of the archive into the current directory:
unzip archive.zip
In a team:
archive.zip
— the name of the archive file.
Unpacking the contents of the archive into the specified directory:
unzip archive.zip -d /path/to/dir
In a team:
archive.zip
- the name of the archive.-d
— unpack to the specified directory./path/to/dir
- path to the specified directory.
7z
Attention!
To avoid possible problems with encoding, unpack archives containing files with Cyrillic names using unar.Unpacking the contents of the archive into the current directory:
7za x archive.7z
In a team:
x
— unpack the contents of the archive.archive.7z
— the name of the archive.
Unpacking the contents of the archive into the specified directory:
7za x archive.7z -o/path/to/dir
In a team:
x
— unpack the contents of the archive.archive.7z
- the name of the archive.-o
— unpack to the specified directory. Attention! There should be no space after the key./path/to/dir
- path to the specified directory. Attention! The path does not have to start with~
.
rar
Attention!
To avoid possible problems with encoding, unpack archives containing files with Cyrillic names using unar.Unpacking the contents of the archive into the current directory:
unrar e archive.rar
In a team:
e
— unpack the contents of the archive.archive.rar
- the name of the archive.
Unpacking the contents of the archive into the specified directory:
unrar e archive.rar /path/to/dir
In a team:
e
— unpack the contents of the archive.archive.rar
- the name of the archive./path/to/dir
- path to the specified directory.
tar
Unzip the contents of the archive into the current directory:
tar -xvf archive.tar
In a team:
-x
— unzip the contents of the archive.-v
— display detailed information.-f
- means that the next argument in the command is the name of the archive.archive.tar
- the name of the archive.
Unzip the contents of the archive to the specified directory:
mkdir /path/to/dir tar -xvf archive.tar -C /path/to/dir
In a team:
-x
— unzip the contents of the archive.-v
— display detailed information.-f
- means that the next argument in the command is the name of the archive.archive.tar
- the name of the archive.-C
— unpack to the specified directory./path/to/dir
- path to the specified directory.
tar.gz
tar.gz
, tar.gzip
or tgz
.
Unpacking the contents of the archive into the current directory:
tar -zxvf archive.tar.gz
In a team:
-z
— unpack the contents of the archive.-x
— unzip the contents of the archive.-v
— display detailed information.-f
- means that the next argument in the command is the name of the archive.archive.tar.gz
- the name of the archive.
Unpacking the contents of the archive into the specified directory:
mkdir /path/to/dir tar -zxvf archive.tar.gz -C /path/to/dir
In a team:
-z
— unpack the contents of the archive.-x
— unzip the contents of the archive.-v
— display detailed information.-f
- means that the next argument in the command is the name of the archive.archive.tar.gz
- the name of the archive.-C
— unpack to the specified directory./path/to/dir
- path to the specified directory.
tar.bz2
tar.bz2
, tar.bzip2
, tbz2
, tb2
or tbz
.
Unpacking the contents of the archive into the current directory:
tar -jxvf archive.tar.bz2
In a team:
-j
— unpack the contents of the archive.-x
— unzip the contents of the archive.-v
— display detailed information.-f
- means that the next argument in the command is the name of the archive.archive.tar.bz2
- the name of the archive.
Unpacking the contents of the archive into the specified directory:
mkdir /path/to/dir tar -jxvf archive.tar.bz2 -C /path/to/dir
In a team:
-j
— unpack the contents of the archive.-x
— unzip the contents of the archive.-v
— display detailed information.-f
- means that the next argument in the command is the name of the archive.archive.tar.bz2
- the name of the archive.-C
— unpack to the specified directory./path/to/dir
- path to the specified directory.