diff options
author | kientzle <kientzle@FreeBSD.org> | 2004-06-07 03:49:48 +0000 |
---|---|---|
committer | kientzle <kientzle@FreeBSD.org> | 2004-06-07 03:49:48 +0000 |
commit | 42e3d5a6499e714d6a10fc6909834c261e418bc5 (patch) | |
tree | 353ec81bae71f6b4897e32c991004aa1cd1912a9 /usr.bin/tar | |
parent | 270635f9583e3b6eb21d37f7c276d1c4e576e91b (diff) | |
download | FreeBSD-src-42e3d5a6499e714d6a10fc6909834c261e418bc5.zip FreeBSD-src-42e3d5a6499e714d6a10fc6909834c261e418bc5.tar.gz |
The --include='pattern' option is the natural counterpart to
--exclude='pattern'.
I should have added this a long time ago, since it's so useful for testing.
In particular, it allows me to select a few entries from a troublesome
archive so that I can easily focus my debugging efforts:
bsdtar -czf new.tgz --include='*foo*' @old.tgz
Diffstat (limited to 'usr.bin/tar')
-rw-r--r-- | usr.bin/tar/bsdtar.1 | 18 | ||||
-rw-r--r-- | usr.bin/tar/bsdtar.c | 7 |
2 files changed, 25 insertions, 0 deletions
diff --git a/usr.bin/tar/bsdtar.1 b/usr.bin/tar/bsdtar.1 index 994d639..4d36d09 100644 --- a/usr.bin/tar/bsdtar.1 +++ b/usr.bin/tar/bsdtar.1 @@ -195,6 +195,24 @@ target of the link will be archived, not the link itself. (c and r mode only) Synonym for .Fl L . +.It Fl -include Ar pattern +Process only files or directories that match the specified pattern. +Note that exclusions specified with +.Fl -exclude +take precedence over inclusions. +If no inclusions are explicitly specified, all entries are processed by +default. +The +.Fl -include +option is especially useful when filtering archives. +For example, the command +.Dl Nm Fl c Fl f Pa new.tar Fl -include='*foo*' Cm @ Ns Pa old.tgz +creates a new archive +.Pa new.tar +containing only the entries from +.Pa old.tgz +containing the string +.Sq foo . .It Fl j (c mode only) Compress the resulting archive with diff --git a/usr.bin/tar/bsdtar.c b/usr.bin/tar/bsdtar.c index ccf7c28..7092fc0 100644 --- a/usr.bin/tar/bsdtar.c +++ b/usr.bin/tar/bsdtar.c @@ -74,6 +74,7 @@ const char *tar_opts = "Bb:C:cF:f:HhjkLlmnOoPprtT:UuvwXxyZz"; #define OPTION_FAST_READ 2 #define OPTION_NODUMP 3 #define OPTION_HELP 4 +#define OPTION_INCLUDE 5 const struct option tar_longopts[] = { { "absolute-paths", no_argument, NULL, 'P' }, @@ -95,6 +96,7 @@ const struct option tar_longopts[] = { { "gunzip", no_argument, NULL, 'z' }, { "gzip", no_argument, NULL, 'z' }, { "help", no_argument, NULL, OPTION_HELP }, + { "include", required_argument, NULL, OPTION_INCLUDE }, { "interactive", no_argument, NULL, 'w' }, { "keep-old-files", no_argument, NULL, 'k' }, { "list", no_argument, NULL, 't' }, @@ -228,6 +230,11 @@ main(int argc, char **argv) long_help(bsdtar); break; #endif +#ifdef HAVE_GETOPT_LONG + case OPTION_INCLUDE: + include(bsdtar, optarg); + break; +#endif case 'j': /* GNU tar */ if (bsdtar->create_compression != '\0') bsdtar_errc(bsdtar, 1, 0, |