1

I have a directory on a NTFS file system which contains files with short and long names, I entered copy command for that directory to be copied on a Ext2 file system, files with short names copied whitout problem but copy files with long names was failed, I recived "File name too long" error, because number of these files is too high I need a shell script to solve the problem in two steps:

1-Copy directory and then delete copied files which have short names (I know move command does it but I want use copy command)

2-Remove between 15 and 20 characters from the end of names of remaining files which have long names, after this I'll repeat the steps until all the files to be copied.

Thank you.

  • Do those file names contain non-ASCII characters? Note that the limit on ext2 is on the number of bytes, not number of characters. Depending on your system's chosen encoding, characters may occupy more than one byte (as in UTF-8 which tends to be the norm these days). – Stéphane Chazelas Apr 27 '15 at 12:32
2

To copy and truncate file names on the fly, you could do:

cd /src &&
LC_ALL=C pax -rws'|\([^/]\{255\}\)[^/]*|\1|g' ./* /dst/

to truncate to 255 byte path components.

Note that it may truncate a file name in the middle of a character if there are multi-byte characters in those file names.

It will also update the targets of symlinks (though I'm not sure ntfs supports symlinks anyway).

Note that you may end-up having files overwriting each other if several files have the same first 255 bytes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.