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

Copying Files Using tar

Copying Files Using tar

One choice for copying files into another location is to use the tar command where you would create a tar file that would be piped to tar to be uncompressed in the new location. To accomplish this, first change to the source directory. Then, the entire command resembles

# tar cvf - files | (cd target_directory ; tar xpf -)

where files are the filenames you want to include; use * to include the entire current directory.

Here is how the command shown works: You have already changed to the source directory and executed tar with the cvf - arguments that tell tar to

c — Create an archive.

v — Be Verbose; lists the files processed so we can see that it is working.

f — Use the filename of the archive will be what follows. (In this case, it is -.)

- — Use a buffer; a place to hold data temporarily.

The following tar commands can be useful for creating file copies for backup purposes:

l — Stay in the local file system (so that you do not include remote volumes).

atime-preserve — Do not change access times on files, even though you are accessing them now, to preserve the old access information for archival purposes.

The contents of the tar file (held temporarily in the buffer, which is named -) are then piped to the second expression, which extracts the files to the target directory. In shell programming (refer to Chapter 10, "Managing Users"), enclosing an expression in parentheses causes it to operate in a subshell and be executed first.

First we change to the target directory, and then

x — Extract files from a tar archive.

? p — Preserve permissions.

f — Read from -, the temporary buffer that holds the tar'ed files.

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


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