Combining commands

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.

To uudecode and gunzip at one time:

1.
ls -l

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.

Code Listing 13.14. Decoding and unzipping at once is a little cryptic, but saves your typity typity fingers.
[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]$

To uncompress and untar at one time:

  • uncompress filename.tar.Z | tar xf -

    At the shell prompt, type uncompress followed by the file name (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).

Code Listing 13.15. After you find the compressed files, you can uncompress and untar them at once, then use ls -ld (long and directory flags) to check your work.
[ejr@hobbes compression]$ ls -l *.Z
-rw-r--r--   1 ejr      users      297027
   Jul 27 10:06 labrea.tar.Z
[ejr@hobbes compression]$ uncompress
   labrea.tar.Z | tar -xf -
[ejr@hobbes compression]$ ls -l l*
-rw-r--r--   1 ejr      users      5011760
   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]$

To tar and gzip at one time:

  • tar cf - Labrea | gzip > labrea.tar.gz

    At the shell prompt, enter your tar command as usual but add a - (and a space) before the file name so the output can be piped. Then, pipe the output to gzip and redirect the output of that to a file name with the tar and gz extensions to show that the file has been tarred and gzipped (Code Listing 13.16).

Code Listing 13.16. You can efficiently tar and gzip all at once as well.
[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.htm
-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]$

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.218.157