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 box—that 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.
[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]$ |
1. | |
2. |
tar -cf tarredfilename.tar Feather
Type tar followed by
|
✓ 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.”