Fedora And Red Hat System Administration/Archives And Compression
Compressing Data
[edit | edit source] This page was last edited 39 months ago, and may be abandoned This page has not been edited since 11 August 2021, but other pages in this book might have been. Check out related changes to see what the state of this book is. You can help by editing and updating this book. Remove {{under construction}} from this page if it is not being actively edited. Ask for help at WB:PROJECTS. |
gzip
and gunzip
[edit | edit source]Under Construction
bzip2
and bunzip2
[edit | edit source]Under Construction
tar
- *NIX Archives
[edit | edit source]Under Construction
Creating a tar
archive
[edit | edit source]To create an uncompressed tar
archive,
the c
and f
options are provided (think 'c' for create and 'f' for filename):
[user@station user]$ tar cf foo.tar file1 file2 file3
The first argument is the name of the archive, in this case foo.tar
.
Any following arguments are the files that are being archived (e.g. file1 file2 file3
).
Usually globbing is used to archive all files of a particular type (e.g. tar cf foo.tar *.cpp
will archive all of the .cpp files in the current directory):
To archive all files and subdirectories within a directory,
the same options are provided,
but the second argument is the .
character which symbolizes the current working directory:
[user@station user]$ tar cf foo.tar .
To compress the contents of the archive one of the z
, J
, or j
options are used.
Each option corresponds to a different compression algorithm, which in order are: gzip
, xz
, and bzip2
.
For example, to create a gzip
compressed archive of the current directory the following would be run:
[user@station user]$ tar cfz foo.tar.gz .
Inspecting a tar
archive
[edit | edit source]Under Construction
Extracting a tar
archive
[edit | edit source]Under Construction
cpio
- Flexible Archiving Tool
[edit | edit source]In general, tar
is the preferred method for creating archives,
but in some cases a particular archive format may be desired and
cpio
provides a greater degree of control over how the archive is
generated at the cost of greater complexity.
Creating a cpio
archive
[edit | edit source]To create a cpio
archive, the -o
option is provided (think 'o' for "The archive is being written out"). cpio
expects a list of files to be provided to its standard input. The list of files is usually provided by piping results from the find command. The -H
option can be used to specify the archive format, see the man page for more information.
[user@station user]$ find playground/ playground/ playground/AUTHORS playground/ChangeLog playground/COPYING playground/foo.txt playground/newfile [user@station user]$ find playground/ | cpio -o >archive 1212 blocks [user@station user]$ ls -l archive -rw-rw-r-- 1 user user 620544 Jan 5 08:49 archive [user@station user]$ file archive archive: cpio archive
Listing contents of an archive with cpio
[edit | edit source]To view the contents of an archive the -i
option is provided
to tell cpio
to expect the archive data on its standard input.
The -t
option is also used then to tell cpio to not extract, but
rather simply list the contents of the archive.
[user@station user]$ cpio -it <archive playground/ playground/AUTHORS playground/ChangeLog playground/COPYING playground/foo.txt playground/newfile 1212 blocks
Extracting an archive with cpio
[edit | edit source]The -i
option is used with a combination of options to tell
it how to extract. Common choices include -d
to tell cpio to
create directories as needed. -m
to reset file modification
times. -R
to change file ownership.
[user@station user]$ cd /tmp [user@station tmp]$ cpio -idm <archive 1212 blocks [user@station tmp]$ find playground/ playground/ playground/AUTHORS playground/ChangeLog playground/COPYING playground/foo.txt playground/newfile
zip
- PKZIP style archives
[edit | edit source]Creating a zip
archive
[edit | edit source][user@station user]$ zip -r playground.zip playground adding: playground/ (stored 0%) adding: playground/AUTHORS (deflated 63%) adding: playground/COPYING (deflated 62%) adding: playground/foo.txt (stored 0%) adding: playground/newfile (deflated 39%) adding: playground/ChangeLog (deflated 70%) [user@station user]$ ls -l playground.zip -rw-r--r-- 1 user user 71607 Jan 11 14:33 playground.zip
Listing contents of a zip
archive
[edit | edit source][user@station user]$ unzip -l playground.zip Archive: playground.zip Length Date Time Name -------- ---- ---- ---- 0 01-11-05 14:33 playground/ 2110 01-11-05 14:32 playground/AUTHORS 17992 01-11-05 14:33 playground/COPYING 22 01-11-05 14:33 playground/foo.txt 44 01-11-05 14:33 playground/newfile 212169 01-11-05 14:32 playground/ChangeLog -------- ------- 232337 6 files
Unpacking a zip
archive
[edit | edit source][user@station user]$ rm -rf playground [user@station user]$ unzip playground.zip Archive: playground.zip creating: playground/ inflating: playground/AUTHORS inflating: playground/COPYING extracting: playground/foo.txt inflating: playground/newfile inflating: playground/ChangeLog
dump
- Filesystem Level Backup
[edit | edit source]Under Construction