1 |
On 2021-05-05 15:10+0100 <nunojsilva@×××××××.pt> (Nuno Silva) wrote: |
2 |
|
3 |
> On 2021-05-05, tastytea wrote: |
4 |
> |
5 |
> > On 2021-05-05 09:33-0400 "Walter Dnes" <waltdnes@××××××××.org> |
6 |
> > wrote: |
7 |
> >> tar version |
8 |
> >> |
9 |
> >> #################################################### |
10 |
> >> tar (GNU tar) 1.34 |
11 |
> >> Copyright (C) 2021 Free Software Foundation, Inc. |
12 |
> >> License GPLv3+: GNU GPL version 3 or later |
13 |
> >> <https://gnu.org/licenses/gpl.html>. This is free software: you are |
14 |
> >> free to change and redistribute it. There is NO WARRANTY, to the |
15 |
> >> extent permitted by law. |
16 |
> >> |
17 |
> >> Written by John Gilmore and Jay Fenlason. |
18 |
> >> #################################################### |
19 |
> >> |
20 |
> >> I'm passing on this solution to help others avoid my frustration |
21 |
> >> and wasted time. If you've done "RTFM" on tar, you'll find out |
22 |
> >> that "TFM" is broken or out-of-date or whatever, re: |
23 |
> >> "--exclude=PATTERN". I'm fighting the urge to turn this into a |
24 |
> >> rant. Here's my situation... |
25 |
> >> |
26 |
> >> I either log in as root or "su -" and then "cd /home". I want to |
27 |
> >> tar up /home/waltdnes, and transfer it to another machine. While |
28 |
> >> I'm at it, I want to exlude directory /home/waltdnes/.cache/ and |
29 |
> >> all *.xz files in directory /home/waltdnes/pm/ The "--exclude=" |
30 |
> >> never worked. After much hair pulling, I was ready to give up on |
31 |
> >> the exclude, and simply transfer all the unnecessary garbage. |
32 |
> >> |
33 |
> >> Then "I asked Mr. Google". It seems that I wasn't the only |
34 |
> >> person running into problems. After some searching, I finally |
35 |
> >> found a syntax that works... |
36 |
> >> |
37 |
> >> #################################################### |
38 |
> >> #!/bin/bash |
39 |
> >> export GZIP=-9 |
40 |
> >> tar cvzf wd.tgz --exclude ".cache/*" --exclude "pm/*.xz" waltdnes |
41 |
> >> #################################################### |
42 |
> >> |
43 |
> >> Notes... |
44 |
> >> |
45 |
> >> 1) This is obviously not in line with the man page. Specifically, |
46 |
> >> "--exclude" is followed by one space, not an equals sign. |
47 |
> >> |
48 |
> >> 2) ***THERE MUST BE EXACTLY ONE SPACE BETWEEN EACH WORD*** |
49 |
> >> |
50 |
> >> 3) All directories and/or files to exclude must be listed as |
51 |
> >> relative paths to the directory being tarred, i.e. last parameter |
52 |
> >> on the command line. |
53 |
> >> |
54 |
> >> 4) I don't know the maximum line-length, which would limit the |
55 |
> >> number of --exclude entries. In those cases, I wonder if |
56 |
> >> "--exclude-from=FILE" works as "--exclude-from FILE". |
57 |
> >> |
58 |
> > |
59 |
> > This works fine here with “tar (GNU tar) 1.34”: |
60 |
> > |
61 |
> > $ mkdir -p a/b |
62 |
> > $ touch a/file a/b/file |
63 |
> > $ touch a/file.xz a/b/file.xz |
64 |
> > $ tree a |
65 |
> > a |
66 |
> > ├── b |
67 |
> > │ ├── file |
68 |
> > │ └── file.xz |
69 |
> > ├── file |
70 |
> > └── file.xz |
71 |
> > |
72 |
> > 1 directory, 4 files |
73 |
> > $ tar -cvzf test.tar.gz --exclude="a/file" --exclude="a/b/*.xz" a |
74 |
> > a/ |
75 |
> > a/file.xz |
76 |
> > a/b/ |
77 |
> > a/b/file |
78 |
> > $ tar -tf test.tar.gz |
79 |
> > a/ |
80 |
> > a/file.xz |
81 |
> > a/b/ |
82 |
> > a/b/file |
83 |
> > |
84 |
> > You can find out the maximum length of the command-line with |
85 |
> > `getconf ARG_MAX`. |
86 |
> |
87 |
> |
88 |
> But does it work with a space instead of = as well? According to the |
89 |
> online manual page, it should work both ways. |
90 |
> |
91 |
|
92 |
Yes. It also works with 10 spaces. |
93 |
|
94 |
-- |
95 |
Get my PGP key with `gpg --locate-keys tastytea@××××××××.de` or at |
96 |
<https://tastytea.de/tastytea.asc>. |