This article discusses the archiving tools available in Linux, with specific reference to the information needed for the RHCSA EX200 and RHCE EX300 certification exams.
Remember, the exams are hands-on, so it doesn't matter which method you use to achieve the result, so long as the end product is correct.
All the commands in this article have many options in addition to the basic ones being used here. Please check the
man
pages for each command. The examples will use the following files.Extracts assume the "/tmp/extract-dir" directory is empty.mkdir -p /tmp/test-dir/subdir1 mkdir -p /tmp/test-dir/subdir2 mkdir -p /tmp/test-dir/subdir3 mkdir -p /tmp/extract-dir touch /tmp/test-dir/subdir1/file1.txt touch /tmp/test-dir/subdir1/file2.txt touch /tmp/test-dir/subdir2/file3.txt touch /tmp/test-dir/subdir2/file4.txt touch /tmp/test-dir/subdir3/file5.txt touch /tmp/test-dir/subdir3/file6.txt
tar
Create an archive.Check the contents.# cd /tmp # tar -cvf archive1.tar test-dir
Extract it.# tar -tvf /tmp/archive1.tar
# cd /tmp/extract-dir # tar -xvf /tmp/archive1.tar
star
Thestar
command may not be installed by default, but you can install it with the following command.Create an archive.# yum install star
Check the contents.# cd /tmp # star -cv f=archive2.star test-dir
Extract it.# star -tv f=/tmp/archive2.star
# cd /tmp/extract-dir # star -xv f=/tmp/archive2.star
gzip
Thegzip
command compresses the specified files, giving them a ".gz" extension. In this case we will use it to compress a ".tar" file.The "-z" option of the# cd /tmp # tar -cvf archive3.tar test-dir # gzip archive3.tar
tar
command allows you to do this directly.The files are uncompressed using the# cd /tmp # tar -cvzf archive3.tar.gz test-dir
gunzip
command.The "-z" option of the# gunzip archive3.tar.gz
tar
command allows you to directly ungzip
and extract a ".tar.gz" file.# cd /tmp/extract-dir # tar -xvzf /tmp/archive3.tar.gz
bzip2
Thebzip2
command is similar to the gzip
command. It compresses the specified files, giving them a ".bz2"
extension. In this case we will use it to compress a ".tar" file.The "-j" option of the# cd /tmp # tar -cvf archive4.tar test-dir # bzip2 archive4.tar
tar
command allows you to do this directly.The files are uncompressed using the# cd /tmp # tar -cvjf archive4.tar.bz2 test-dir
bunzip2
command.The "-j" option of the# bunzip2 archive4.tar.bz2
tar
command allows you to directly bunzip2
and extract a ".tar.bz2" file.# cd /tmp/extract-dir # tar -xvjf /tmp/archive4.tar.bz2
zip
Create an archive.Check the contents.# cd /tmp # zip -r archive5.zip test-dir
Extract it.# unzip -l archive5.zip
# cd /tmp/extract-dir # unzip /tmp/archive5.zip
cpio
Create an archive.Check the contents.# cd /tmp # find test-dir | cpio -ov > archive6.cpio
Extract it.# cpio -t < /tmp/archive6.cpio
# cd /tmp/extract-dir # cpio -idmv < /tmp/archive6.cpio
No comments:
Post a Comment