4

I'm running tar as root like this:

cd /
tar --create                    \
    --verify                    \
    --exclude-backups           \
    --exclude-caches            \
    --auto-compress             \
    --file /tmp/home.tar.gz     \
    --exclude=/home/elena/.gvfs \
    home

tar outputs:

tar: home/elena/.gvfs: Cannot stat: Permission denied

I would expect the .gvfs[1] directory to be ignored completely. Why is GNU tar running stat over it?

As to why I'm using /home/elena/.gvfs - an absolute path - to match the .gvfs directory, it is because - to my knowledge - there is no other way to select single directories for exclusion without excluding matching subdirectories at any level as well.

I've tried putting the --exclude line after home, to take possible quirks in different versions of tar into account, but that changes nothing.

Thanks for your attention.

GNU tar version: 1.23

--

[1] ~/.gvfs is a way to access the Gnome Virtual File System I'm skipping it because I know it can't be accessed, and it doesn't make sense to archive it. I still wonder why tar doesn't skip it completely.

Eleno
  • 1,849
  • What are the permissions on /home/elena/.gvfs? – MattDMo Jul 12 '13 at 14:32
  • @MattDMo: I have no idea: even ls -l /home/elena/.gvfs as root fails because of denied access. However, I know that .gvfs is a way to access the Gnome Virtual File System: http://en.wikipedia.org/wiki/GVFS

    I'm skipping it because I know it can't be accessed, and it doesn't make sense to archive it.

    – Eleno Jul 12 '13 at 14:57
  • Try running ls -al /home/elena and let us know what the entire .gvfs line says. This way, you're not trying to read the contents of .gvfs as ls -l /home/elena/.gvfs is doing. Also, can you read /home/elena/.gvfs as user elena, not root? – MattDMo Jul 12 '13 at 17:22
  • Run as root, permission denied again:

    ls: cannot access /home/elena/.gvfs: Permission denied.

    And the .gvfs line reads:

    d?????????? ? ? ? ? ? .gvfs

    It's the only item in the output of ls that looks weird.

    – Eleno Jul 12 '13 at 17:51
  • Are those question marks? Sorry, I'm on XP (Firefox 22) and what you posted just showed up as d?????????? ? ? ? ? ? (approximately, I just typed that in...) – MattDMo Jul 12 '13 at 18:35
  • could you post a screenshot? This looks really weird... – MattDMo Jul 12 '13 at 18:47

1 Answers1

0
tar: home/elena/.gvfs: Cannot stat: Permission denied

Notice that the error message doesn't include a leading slash. Try --exclude=home/elena/.gvfs without the slash.

Karlson
  • 5,875
  • Thank you, but I can't. Otherwise the pattern could match subdirectories at every level, and I don't want that. – Eleno Jul 12 '13 at 13:07
  • Then you can't exclude it. – tripleee Jul 12 '13 at 13:09
  • Hence tar doesn't allow for fine-grained control on what directories and files end up in an archive? – Eleno Jul 12 '13 at 13:26
  • Not by itself, as far as I understand the documentation. The workaround is to find | grep - v stuff | xargs tar or some approximation of that. – tripleee Jul 12 '13 at 14:23
  • 2
    @Elena Try also adding option --anchored. Than would match the initial part of the path name even without slash. – eppesuig Jul 12 '13 at 15:26
  • @eppesuig: Thanks, but I can't. The command in my question is not complete. The complete version needs to filter files in subdirectories based on their extension, and --anchored wouldn't allow that. Or am I allowed to mix --anchored and --no-anchored patterns? – Eleno Jul 12 '13 at 15:48
  • @Elena, yes you can mix --anchored and --no-anchored. The example in the manual uses --ignore-case, but it applies to --anchored and --wildcards-match-slash too. – cjm Jul 12 '13 at 16:10
  • @tripleee -- | tar --files-from - ... would work as well – sendmoreinfo Jul 12 '13 at 18:31
  • @sendmoreinfo: thanks for the tip; that's better than xargs actually. – tripleee Jul 12 '13 at 19:01