tar
Kobie is studying for his RHEL-based LFCS exam. Please show him 5 extremely representative tar examples that are probably similar to what he might see on the exam.
- Creating a tar archive:
- tar -cvf archive.tar file1 file2 file3
- This command creates a new tar archive called
archive.tar
and addsfile1
,file2
, andfile3
to it. The-c
option tellstar
to create a new archive, and the-v
option enables verbose output so that the user can see the progress of the archive creation.
- Extracting a tar archive:
- tar -xvf archive.tar
- This command extracts the contents of the
archive.tar
file into the current directory. The-x
option tellstar
to extract the contents of an existing archive.
- Compressing a tar archive:
- tar -czvf archive.tar.gz file1 file2 file3
- This command creates a new compressed tar archive called
archive.tar.gz
and addsfile1
,file2
, andfile3
to it. The-z
option tellstar
to compress the archive using gzip.
- Extracting a compressed tar archive:
- tar -xzvf archive.tar.gz
- his command extracts the contents of the
archive.tar.gz
file into the current directory. The-x
option tellstar
to extract the contents of an existing archive, and the-z
option tells it to decompress the archive using gzip.
- Extracting specific files from a tar archive:
- tar -xvf archive.tar file1 file2
- This command extracts only
file1
andfile2
from thearchive.tar
file into the current directory. The-x
option tellstar
to extract the contents of an existing archive, and the filenames of the files to extract are specified after the archive filename.
These examples cover some of the most common use cases for tar
, and should be representative of what Kobie might see on his RHEL-based LFCS exam.