Книга: Fedora™ Unleashed, 2008 edition

Working with Compressed Files

Working with Compressed Files

Another file management operation is compression and decompression of files, or the creation, listing, and expansion of file and directory archives. Linux distributions usually include several compression utilities you can use to create, compress, expand, or list the contents of compressed files and archives. These commands include the following:

bunzip2 — Expands a compressed file

bzip2 — Compresses or expands files and directories

gunzip — Expands a compressed file

gzip — Compresses or expands files and directories

shar file — Creates a shell archive of files

tar — Creates, expands, or lists the contents of compressed or uncompressed file or directory archives known as tape archives or tarballs

Most of these commands are easy to use. The tar command, however, has a somewhat complex (although capable) set of command-line options and syntax. Even so, you can quickly learn to use tar by remembering a few simple invocations on the command line. For example, to create a compressed archive of a directory, use tar's czf options like this:

$ tar czf dirname.tgz dirname

The result is a compressed archive (a file ending in .tgz) of the specified directory (and all files and directories under it). Add the letter v to the preceding options to view the list of files added during compression and archiving. To list the contents of the compressed archive, substitute the c option with the letter t, as follows:

$ tar tzf archive

Of course, if many files are in the archive, a better invocation (to easily read or scroll through the output) is the following:

$ tar tzf archive | less

To expand the contents of a compressed archive, use tar's zxf options, like so:

$ tar zxf archive

The tar utility decompresses the specified archive and extracts the contents in the current directory.

Оглавление книги


Генерация: 0.068. Запросов К БД/Cache: 0 / 0
поделиться
Вверх Вниз