RH124 Ch 13: Archiving and Transferring Files

tar bundles files into one archive and can compress it. - Create: tar czf etc.tar.gz /etc (gzip), tar cjf x.tar.bz2 dir (bzip2), tar cJf x.tar.xz dir (xz). - List: tar tf archive. Extract: tar xf archive -C /target (tar detects the compression when reading). - tar strips the leading /, so /etc/hosts is stored as etc/hosts and extracts relative to -C. - Useful extras: -v verbose, -p keep permissions when extracting, --selinux --acls --xattrs keep extended attributes. - Single files: gzip/gunzip, bzip2/bunzip2, xz/unxz. xz compresses best but slowest, gzip is fastest.

Copying over SSH - scp file user@host:/path/ and scp user@host:/path/file . — remote paths without a leading / are relative to the remote home. -r for directories. - sftp user@host gives an interactive session: ls, cd, put, get, exit. - rsync -av src/ user@host:dest/ copies only differences. -a keeps permissions, times, links and owners (as root); -v is verbose; --delete mirrors removals; -n is a dry run. - A trailing / on the rsync source copies the contents; without it the directory itself is created inside the destination.

Exam traps - Mixing up z, j and J — check with file archive. - Archiving /etc as a normal user and silently missing unreadable files. - Using cp/scp when timestamps and modes must be preserved — use rsync -a or scp -p.