[Chapter 20] 20.9 When a Program Doesn't Understand Wildcards
Author: Jerry Peek, Tim O'Reilly & Mike Loukides
Date: 1998-10-23T15:45:01Z

#

| Chapter 20 Backing Up Files |

## 20.9 When a Program Doesn't Understand Wildcards

When extracting files from a tar archive, it's handy to be able to use wildcards. You have to protect them (8.14) from the shell, so that they are passed directly to tar.

However, in general tar don't understand wildcards. There's a terribly ugly hack that you can use to select the files you want anyway. Try a command like this:

    `...`
    % tar xvf /dev/rst0 `tar tf /dev/rst0 | egrep  'lib/(foo|bar)'`

What you're doing here is using tar twice. tar t will print the names of all the files on the tape. The pattern supplied to egrep (27.5) selects the pathnames containg lib/foo or lib/bar, and the resulting filenames are passed to the first tar command, which actually extracts the files from the archive.

- TOR

20.8 Telling tar Which Files to Exclude or Include |  | 20.10 Avoid Absolute Paths with tar