From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id E15591382C5 for ; Wed, 5 May 2021 14:11:11 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id F2299E087B; Wed, 5 May 2021 14:11:06 +0000 (UTC) Received: from ciao.gmane.io (ciao.gmane.io [116.202.254.214]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id A0E6CE086F for ; Wed, 5 May 2021 14:11:06 +0000 (UTC) Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1leIEy-00029H-Jg for gentoo-user@lists.gentoo.org; Wed, 05 May 2021 16:11:04 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: gentoo-user@lists.gentoo.org From: (Nuno Silva) Subject: [gentoo-user] Re: [OT] tar exclude syntax tip Date: Wed, 05 May 2021 15:10:58 +0100 Message-ID: References: <20210505160303.58ba6a67@ventiloplattform.tastytea.de> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-user@lists.gentoo.org Reply-to: gentoo-user@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) X-Archives-Salt: f344872a-0996-45ea-a0ab-b72e9d4ddc9f X-Archives-Hash: 4fd824ce0c31b09c5c81acbc5bd4170d On 2021-05-05, tastytea wrote: > On 2021-05-05 09:33-0400 "Walter Dnes" wrote: > >> tar version >> >> #################################################### >> tar (GNU tar) 1.34 >> Copyright (C) 2021 Free Software Foundation, Inc. >> License GPLv3+: GNU GPL version 3 or later >> . 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. -- Nuno Silva