'tar' stands for "TApe ARchive".
Create a tar archive
tax -cvf [archive].tar [file(s)|folder]
Extract a tar archive
tar -xvf [archive].tar
Show all files of an archive:
tar -tvf [archive].tar
With gunzip
Create a compressed tar archive
tar -czvf [archive].tar.gz [file(s)|folder]
Extract a compressed tar archive
tar -xzvf [archive].tar.gz
With bzip2
Create compressed tar archive
tar -cjvf [archive].tar.bz2 [file(s)|folder]
Extract a compressed tar archive
tar -xjvf [archive].tar.bz2
star is another implementation of tar. It looks like it supported SELinux context before tar (however tar now also supports extended file attributes as well as SELinux, so I'm not sure if this is really needed for the exam).
Create an archive
# star -c –f=compressed.star [file list]
Extract archive
# star –x –f=compressed.star
Create an archive retaining SELinux context
# star -xattr -H=exustar -c -f=test.star file{1,2,3}
Snippet from RHEL 6 documentation page
The main difference between the different compress commands is the algorithm that they use.
Compression commands:
Create a compressed file
gzip file
Result: file.gz
Decompress a file:
gzip -d file
Create a compressed file
bzip2 file
Result: file.bz2
Decompress a file
bzip2 -d file.bz2
Combining individual files in a compressed archive:
zip archive.zip file1 file2
Combining complete folders in a compressed archive:
zip -r archive.zip folder1 folder2 folder3
Decompress and extract an archive:
unzip archive.zip
Show all files of an archive:
unzip -l archive.zip
Notes:
-d
on both gzip
and bzip2
to extract. For unzip
, the command itself specifies that it's extracting (-d
is used for destination folder)-5
)You can use the following commands to view compressed files:
zcat
gunzip -c
bzip2 -c
zless
vim