As we’ve shown you in this chapter, you use separate commands to encode/unencode, tar/untar, compress/uncompress, and zip/ unzip files and directories. A lot of times, however, you can pipe commands together and run them in sequence, saving you time and hassle. For example, as Code Listing 13.14 shows, you can uudecode and gunzip files at the same time by piping the commands together. You can also uncompress and untar at one time, and you can tar and gzip at one time.
1. | ls -l h*
Use ls -l to verify the existence of your uuencoded and zipped file. |
2. | uudecode -o /dev/stdout home.gz.uue
→ | gunzip > home
Here, we use -o /dev/stdout to send the uudecode output to the standard output, then pipe the output of the uudecode command to gunzip, then redirect the output of gunzip to the home file. Whew! See Code Listing 13.14 for the details. |
[ejr@hobbes compression]$ ls -l h* -rw-rw-r- 1 ejr users 73978 Jul 23 11:15 home.gz.uue -rw-r-r- 1 ejr users 177607 Jul 27 09:34 house.uue [ejr@hobbes compression]$ uudecode -o /dev/stdout home.gz.uue | gunzip > home [ejr@hobbes compression]$ ls -l h* -rw-r-r- 1 ejr users 128886 Jul 27 10:48 home -rw-rw-r- 1 ejr users 73978 Jul 23 11:15 home.gz.uue -rw-r-r- 1 ejr users 177607 Jul 27 09:34 house.uue [ejr@hobbes compression]$ |
zcat filename.tar.Z | tar -xf -
At the shell prompt, type zcat followed by the filename (as usual) and pipe that output to tar. Follow the tar command and flags with a - so that tar will be able to save the file to the intended name (Code Listing 13.15).
[ejr@hobbes compression]$ ls -l *.Z -rw-r-r-1 ejr users 297027 Jul 27 → 10:06 labrea.tar.Z [ejr@hobbes compression]$ zcat → labrea.tar.Z | tar -xf - [ejr@hobbes compression]$ ls -l l* -rw-r-r-1 ejr users 501760 Jul 27 → 10:06 labrea.tar [ejr@hobbes compression]$ ls -ld L* drwxr-xr-x 2 ejr users 1024 Jul 27 → 10:16 Labrea [ejr@hobbes compression]$ |
tar -cf - Feather | gzip > → feather.tar.gz
At the shell prompt, enter your tar command as usual but add a – (and a space) before the filename so the output can be piped. Then, pipe the output to gzip and redirect the output of that to a filename with the .tar and .gz extensions to show that the file has been tarred and gzipped (Code Listing 13.16).
[ejr@hobbes compression]$ ls -ld F* drwxrwxr-x 2 ejr users 1024 Jul 23 10:56 Feather [ejr@hobbes compression]$ tar -cf - Feather | gzip > feather.tar.gz [ejr@hobbes compression]$ ls -l f* -rw-r-r-1 ejr users 106752 Jul 27 10:54 feather.tar.gz -rw-rw-r- 1 ejr users 128886 Jul 23 11:45 file1.htm -rw-rw-r- 1 ejr users 128886 Jul 23 11:45 file2.html -rw-rw-r- 1 ejr users 686080 Jul 23 10:41 folder.tar -rw-rw-r- 1 ejr users 268156 Jul 23 06:53 folderzip.zip -rw-rw-r- 1 ejr users 128886 Jul 23 06:37 fortunes1.txt -rw-rw-r- 1 ejr users 55124 Jul 23 06:38 fortunes1.zip [ejr@hobbes compression] |