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.tarand addsfile1,file2, andfile3to it. The-coption tellstarto create a new archive, and the-voption 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.tarfile into the current directory. The-xoption tellstarto 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.gzand addsfile1,file2, andfile3to it. The-zoption tellstarto compress the archive using gzip.
- Extracting a compressed tar archive:
- tar -xzvf archive.tar.gz
- his command extracts the contents of the
archive.tar.gzfile into the current directory. The-xoption tellstarto extract the contents of an existing archive, and the-zoption 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
file1andfile2from thearchive.tarfile into the current directory. The-xoption tellstarto 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.
