One choice for copying files into another location would be 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 sudo 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 Verbose; lists the files processed so we can see that it is working. f The filename of the archive will be what follows. (In this case, it is -.) - A buffer; a place to hold our data temporarily. The following tar commands can be useful for creating file copies for backup purposes: l Stay in the local file system (so 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 for us temporarily in the buffer, which is named -) are then piped to the second expression, which will extract the files to the target directory. In shell programming (refer to Chapter 15, "Automating Tasks"), 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 The filename will be -, the temporary buffer that holds the tared files.
Was this article helpful?