Archives (tar and cpio) Hour 20 PObjectives < Tape archives: the tar command < cpio archives: the cpio (copy in and out) command < File compression: compress/uncompress, gzip/gunzip, pack/unpack Copyright © 1998-2002 Delroy A. Brinkerhoff. All Rights Reserved. Hour 20 Unix Slide 1 of 7 The tar Command The original Unix archive command Ptar (tape archive) has been around since the early days < it creates a file that contains many files (much like a zip file) < does not compress the contained files < tar recursively descends directories names are arguments Ptar -c|-x|-t [-vo] [-f archive] file-dir ... < -c create archive < -x extract files from archive < -t print table of contents of archive < -v verbose < -o change owner of extracted files < -f archive file or device (– is stdin/stdout) Hour 20 Unix Slide 2 of 7 The cpio Command The new archive command Pcpio (copy in/out) is newer than tar < it’s a little more efficient < it only reads and writes standard in and standard out Pcpio -o [-cvB] < input > output Pcpio -i [-cvtdB] < input Pcpio -p directory < input < -o (create archive) input is a list of files, output is a cpio archive < -i (extract from archive) input is a cpio archive; files are extracted < -p input is a list of files to be copied to directory < -c write header information in ascii (portable) < -v verbose < -d create directories when necessary (during extraction) < -B use 5120 byte blocks (for faster tape access) < -t table of contents (suppresses extraction) Hour 20 Unix Slide 3 of 7 Examples Creating and reading archives Ptar -tvf /dev/rmt/c0s0 Ptar -xvf /dev/rmt/c0s0 Ptar -xvof /tmp/save prog.c job.c Ptar -cvf ../save . Pcpio -o < /tmp/list > /backup/monday Pfind /home -print | cpio -ocB > /backup/monday Pcpio -icvtB < /dev/rmt/c0s0 | more Pcpio -icvdB < /dev/rmt/c0s0 Pcpio -ocvB < /tmp/list > /dev/rmt/c0s0 Hour 20 Unix Slide 4 of 7 Compressing & Decompressing Files Shrinking files Pcompress [-cv] [file] / uncompress [-cv] [file] (p. 84) < -c send output to stdout (else replaces the file, see Hour 8) < -v verbose (progress/status information written to screen) < compressed files end in .Z < zcat file ... extracts to standard out without modifying compressed file Pgzip [-dhv] [file ...] / gunzip [-hv] [file ...] < -d decompress (gzip -d / gunzip) < -h print help screen < -v verbose < compressed files end in .gz < gmore file ... extracts and pages without modifying compressed file Ppack [file ...] / unpack file ... < compressed files end in .z < pcat file ... extracts to standard out without modifying compressed file Hour 20 Unix Slide 5 of 7 Compression Compared Time and compression Original text file size: 134,070 bytes Utility compress time decompress time final size compress 0.38 0.27 57,913 gzip 1.16 0.42 46,087 gzip -1 0.54 0.40 55,125 gizp -9 1.15 0.47 45,971 pack 0.30 0.37 79,694 WinZip — — 46,065 Hour 20 Unix Slide 6 of 7 Notes On Compression Miscellaneous thoughts PCompressed files are binary even if the original was text! PCompressing a compressed file usually results in a larger file and rarely squeezes more than a few more bytes out < It is impossible to keep compressing until you reach an arbitrarily small size PRandom binary files cannot be compressed Pgzip and winzip use dynamic Huffman encoding <most common character (byte) replaced with one bit (the other single-bit pattern is saved as a separator) < three next most common replaced by two bits (the other two-bit pattern is saved as a separator) < seven next most common are replaced by three bits < etc. Hour 20 Unix Slide 7 of 7 .
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages4 Page
-
File Size-