delavnog delavnog - 2 months ago 7
Linux Question

Problems untarring files with long names in linux

Coming from windows, via tar file generated with 7z. I am having trouble with some long file names:

tar: xxxxxxx: Cannot open: File name too long


It seems Linux (or tar?) has a 256 character limit for filenames. Fair enough. I am trying to limit the length using the
--xform
option:

tar -x --xform 's/^\(.\{200\}\).*/\1/' -f japanese.tar


But this does not work. The sed expression is working though:

$ echo whateverwhateverwhateverwhateverwhateverwhateverwhatever | sed -e 's/^\(.\{10\}\).*/\1/'
whateverwh


Is the sed expression not supported by tar? Any other way to shorten the names?

Answer

You excluded file extension in your expression. Could you try this;

tar -x --xform 's/^\(.\{200\}\).*\(\.[^.]*\)/\1\2/' -f japanese.tar

eg:

user@host:/tmp/test$ echo whateverwhateverwhateverwhateverwhateverwhateverwhatever.txt | sed -e 's/^\(.\{10\}\).*/\1/'
whateverwh
user@host:/tmp/test$ echo whateverwhateverwhateverwhateverwhateverwhateverwhatever.txt | sed 's/^\(.\{10\}\).*\(\.[^.]*\)/\1\2/'
whateverwh.txt