public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
From: tastytea <gentoo@tastytea.de>
To: gentoo-user@lists.gentoo.org
Subject: Re: [gentoo-user] Re: [OT] tar exclude syntax tip
Date: Wed, 5 May 2021 16:23:49 +0200	[thread overview]
Message-ID: <20210505162349.06cdc970@ventiloplattform.tastytea.de> (raw)
In-Reply-To: <s6u91i$14pp$1@ciao.gmane.io>

[-- Attachment #1: Type: text/plain, Size: 3376 bytes --]

On 2021-05-05 15:10+0100 <nunojsilva@ist.utl.pt> (Nuno Silva) wrote:

> On 2021-05-05, tastytea wrote:
> 
> > On 2021-05-05 09:33-0400 "Walter Dnes" <waltdnes@waltdnes.org>
> > wrote: 
> >>   tar version
> >> 
> >> ####################################################
> >> tar (GNU tar) 1.34
> >> Copyright (C) 2021 Free Software Foundation, Inc.
> >> License GPLv3+: GNU GPL version 3 or later
> >> <https://gnu.org/licenses/gpl.html>. This is free software: you are
> >> free to change and redistribute it. There is NO WARRANTY, to the
> >> extent permitted by law.
> >> 
> >> Written by John Gilmore and Jay Fenlason.
> >> ####################################################
> >> 
> >>   I'm passing on this solution to help others avoid my frustration
> >> and wasted time.  If you've done "RTFM" on tar, you'll find out
> >> that "TFM" is broken or out-of-date or whatever, re:
> >> "--exclude=PATTERN".  I'm fighting the urge to turn this into a
> >> rant.  Here's my situation...
> >> 
> >>   I either log in as root or "su -" and then "cd /home".  I want to
> >> tar up /home/waltdnes, and transfer it to another machine.  While
> >> I'm at it, I want to exlude directory /home/waltdnes/.cache/ and
> >> all *.xz files in directory /home/waltdnes/pm/  The "--exclude="
> >> never worked. After much hair pulling, I was ready to give up on
> >> the exclude, and simply transfer all the unnecessary garbage.
> >> 
> >>   Then "I asked Mr. Google".  It seems that I wasn't the only
> >> person running into problems.  After some searching, I finally
> >> found a syntax that works...
> >> 
> >> ####################################################
> >> #!/bin/bash
> >> export GZIP=-9
> >> tar cvzf wd.tgz --exclude ".cache/*" --exclude "pm/*.xz" waltdnes
> >> ####################################################
> >> 
> >> Notes...
> >> 
> >> 1) This is obviously not in line with the man page.  Specifically,
> >> "--exclude" is followed by one space, not an equals sign.
> >> 
> >> 2) ***THERE MUST BE EXACTLY ONE SPACE BETWEEN EACH WORD***
> >> 
> >> 3) All directories and/or files to exclude must be listed as
> >> relative paths to the directory being tarred, i.e. last parameter
> >> on the command line.
> >> 
> >> 4) I don't know the maximum line-length, which would limit the
> >> number of --exclude entries.  In those cases, I wonder if
> >> "--exclude-from=FILE" works as "--exclude-from FILE".
> >>   
> >
> > This works fine here with “tar (GNU tar) 1.34”:
> >
> > $ mkdir -p a/b
> > $ touch a/file a/b/file
> > $ touch a/file.xz a/b/file.xz
> > $ tree a
> > a
> > ├── b
> > │   ├── file
> > │   └── file.xz
> > ├── file
> > └── file.xz
> >
> > 1 directory, 4 files
> > $ tar -cvzf test.tar.gz --exclude="a/file" --exclude="a/b/*.xz" a
> > a/
> > a/file.xz
> > a/b/
> > a/b/file
> > $ tar -tf test.tar.gz
> > a/
> > a/file.xz
> > a/b/
> > a/b/file
> >
> > You can find out the maximum length of the command-line with 
> > `getconf ARG_MAX`.  
> 
> 
> But does it work with a space instead of = as well? According to the
> online manual page, it should work both ways.
> 

Yes. It also works with 10 spaces.

-- 
Get my PGP key with `gpg --locate-keys tastytea@tastytea.de` or at
<https://tastytea.de/tastytea.asc>.

[-- Attachment #2: Digitale Signatur von OpenPGP --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2021-05-05 14:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-05 13:33 [gentoo-user] [OT] tar exclude syntax tip Walter Dnes
2021-05-05 14:03 ` tastytea
2021-05-05 14:10   ` [gentoo-user] " Nuno Silva
2021-05-05 14:23     ` tastytea [this message]
2021-05-05 15:28   ` [gentoo-user] " Walter Dnes
2021-05-05 16:00     ` tastytea
2021-05-05 15:20 ` Grant Taylor
2021-05-06  0:07 ` Frank Steinmetzger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210505162349.06cdc970@ventiloplattform.tastytea.de \
    --to=gentoo@tastytea.de \
    --cc=gentoo-user@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox