7

I made a tar with a directory on a remote machine with:

tar -czvf

I scp it to my local machine, where I wanted to untar it:

tar -xzvf

But I get : Cannot open: File name too long

On my local machine on lubuntu 12.04 I have: tar (GNU tar) 1.26.

The remote machine is not accessible right now, I'll check the version after if needed.

I would like to extract without having to make a new tar, especially since the remote machine is offline.

And by the way if you know a way to make proper archive despite long name, I'll take it.

3
  • In the future, you may want to use rsync instead of scp and tar. rsync can transfer in compressed format by setting the right flags.
    – Bernhard
    Commented Nov 20, 2012 at 11:45
  • I 'll consider that, even if in this case the tar was made because I need large files in the remote machine. Thanks Bernhard.
    – mthpvg
    Commented Nov 20, 2012 at 13:55
  • Same problem might appear as tar: [...] Cannot mkdir: File name too long. Appeared on an encrypted filesystem when uncompressing a tar taken on a non-encrypted filesystem. Commented May 15, 2013 at 10:47

2 Answers 2

7

tar limit file names to 256 bytes (with GNU extensions). Linux File Systems support at least 256 bytes per file name. It means any file packed by tar may be extracted without error. So I suppose two causes:

  1. The tarball is corrupted, check it by:

    $ tar -tvf tarball.tar
    

    You will see some erros if any.

  2. You use a "virtual" file system like fusecompress or ecryptfs (with selective file copmpression/encryption) and your file name is a bit shorter or equal to the file system limit. The trick is when you mount a directory with fusecompress (for example) and create a file name foo.bar the virtual filesystem creates a file called foo.bar.gz and compress it transparently, but hides the real file name from you. And if you create a file with 254 byte name long you get an error because it will try to append a suffix to it.

    In this case simply extracting the tarball outside of the virtual file system should help:

    $ sudo mkdir /home/${USER}-temp
    $ sudo chown $USER /home/${USER}-temp
    $ tar -xvf tarball.tar -C /home/${USER}-temp
    

Anyway, try to trace it to get more information:

$ strace -o tar-strace.log tar -tf tarball.tar
$ ltrace -o tar-ltrace.log tar -tf tarball.tar
3
  • It is not a virtual file system. I have like thousands of files, there is one which is 158 caracters long without the path to it (with it it's 219). It starting and ending with a "#". I do not know this file, I guess if I removed it before "taring" it will work. The "tar -tvf" shows nothing special... and I do not know how to read the trace files (which are pretty long). Thanks a lot Dmitry.
    – mthpvg
    Commented Nov 20, 2012 at 13:53
  • 1
    Linux File Systems usually don't limit path length (see comparsion table). As for trace logs - if you're not aware with programming you could place files at pastebin.com for example, but first ensure files contain no private data. Also if you don't need this particular file then you could just try to exclude it on extraction: tar tar -xvf tarball.tar --exclude="copyFileNameHere" or even exclude all files starting with the sharp sign: tar -xvf tarball.tar --exclude="#*"
    – Dmitry
    Commented Nov 20, 2012 at 14:17
  • I can't paste them unfortunately (it is not my data). Thanks for your answer and this comment, I'll use it !
    – mthpvg
    Commented Nov 20, 2012 at 14:22
1

Here is my workaround to save the files. When extracting tar, add these options:

  • use --xform '/sed/expression/' to abbreviate the long names.
  • use -T file_with_names_list to only extract problematic files rather than all archive.

Example:

put the long file names to /tmp/missing.txt first.

tar -x -T /tmp/missing.txt --xform 's/Beethoven-.*\.flac/B.flac/g' -f backup/home.tar

In my case all the problematic files were numbered audio tracks with metainformation, so clipping a bit of a name did not seem like an issue. You may need to think of a way to restore the original file name.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .