Archiving with tar


Archiving with tar

Occasionally, you'll want to take a bunch of files and make them into one file, such as when you're archiving information, for example. You might think of it as tossing a bunch of toys into a toy boxthat is, taking a bunch of related things and storing them all in one place.

Using tar (which came from "tape archive"), you can take a bunch of files and store them as a single, uncompressed file (see Code Listing 13.5). You'll use tar files not only to store information, but also to create a single source for compressing and gzipping files, which are discussed later in this chapter.

Code Listing 13.5. Tarring files binds them all together into a single file.

[ejr@hobbes compression]$ ls -l total 2290 drwxrwxr-x    2 ejr     users    1024 Jul 23 10:56 Feather drwxrwxr-x    2 ejr     users    1024 Jul 23 10:49 Zipadeedoodah -rw-rw-r-     1 ejr     users    53678 Jul 23 06:42 bigfile.gz -rw-rw-r-     1 ejr     users    53678 Jul 23 10:16 bigfile.new.gz -rw-rw-r-     1 ejr     users    73989 Jul 23 10:16 bigfile.uue -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 -rw-rw-r-     1 ejr     users    0 Jul 23 11:21 gzip -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 -rw-rw-r-     1 ejr     users    53792 Jul 23 06:52 newzip.zip -rw-rw-r-     1 ejr     users    128886 Jul 23 08:19 ournewhouse.jpg -rw-rw-r-     1 ejr     users    128886 Jul 27 09:52 rowboat.jpg -rw-r-r-      1 ejr     users    177606 Jul 27 09:51 rowboat.uue drwxrwxr-x    3 ejr     users    1024 Jul 23 12:56 temp [ejr@hobbes compression]$ tar -cf tarredfilename.tar Feather [ejr@hobbes compression]$ 

To Archive a Directory with tar:

1.

ls -l

For starters, type ls -l at the shell prompt to verify the name of the directory you're going to tar.

2.

tar -cf tarredfilename.tar Feather

Type tar followed by

  • The -cf flags (to create a file)

  • The name you want the tarred (archived) file to have (tarredfilename.tar in this example)

  • The name (or names) of the directory or files to tar (Feather, here)

Tips

  • See the section called Combining Commands later in this chapter for timesaving ideas for combining and compressing files all in one fell swoop.

  • Some versions of tar also support gzip, so you can use tar czf tarredfilename.tgz Feather to tar and gzip all at once.

  • You can add the v flag to the tar command flags (-vcf) to get a verbose description of what's being tarred.

  • If you want to sound like a real Unix geek, refer to tarred files as "tarballs."





Unix(c) Visual Quickstart Guide
UNIX, Third Edition
ISBN: 0321442458
EAN: 2147483647
Year: 2006
Pages: 251

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net