3

I am on linux ubuntu 16 and I need to copy around 400gb(some 100.000 files) of data from my HDD to my SSD. This I can't do because around 1000 of those files have "too long name" and I can't just skip them since it will take a long time to find them. Any program that copies files with long names?

closed as unclear what you're asking by Gilles, Jeff Schaller, Eric Renouf, Patrick, Anthon Apr 17 '17 at 12:28

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    What filesystem is it that you're using that does not support these names? MSDOS? Would you be able to put the files in a tar archive and transfer that instead? – Kusalananda Apr 16 '17 at 21:06
  • What filesystems are they? What are you using to copy the files? If something like cp on the command line, shouldn't you get an error printed out for them? – ilkkachu Apr 16 '17 at 21:06
  • It's not terribly difficult to compare two lists of filenames. Try cd /path1 && find . -type f | sort >/tmp/list1 then repeat for path2 and list2. Use sdiff /tmp/list1 /tmp/list2 to see differences or comm -3 /tmp/list1 /tmp/list2 to see files in list1 that aren't in list2 and v.v. – roaima Apr 16 '17 at 21:22
  • 3
    If there's a limit on file name length, it's probably due to the filesystem(s), not to the tool you used. (I say “probably” because you didn't say which tool you used, so it's possible that you found some weird unusual tool that has a limitation.) What are examples of files whose name is too long, and what filesystem type are you copying them to? – Gilles Apr 16 '17 at 21:39
  • 1
    Do you use home folder encryption? I'm asking because the home folder encryption Ubuntu uses prohibits files with a name longer than 144ish characters, whereas usually on ext{2, 3, 4}, you can use file names with up to 255 (not 255ish) characters. – UTF-8 Apr 16 '17 at 22:38
-3

Original (wrong) answer

Cool guys told, that rsync works like a charm:

rsync -auv --exclude '.svn' --exclude '*.pyc' source destination

Original answer: https://superuser.com/a/29437/483428

UPD: with script

ok, other cool guys told, that rsync is not a solution, when filesystem itself doesn't support long names. I'll take note, that rsync is not a metaphysical low-level super secret tool, made by gods (there are a lot of such tools for Windows, btw;)

So, here is a short python script (python 2.7 is installed by default on Ubuntu, as I know), which copies all files from SRC to DST, and will print names of files, caused errors (including, long names)

  1. Save it as copy.py
  2. Usage: python copy.py SRC DEST
import os
import sys
import shutil

def error_on_dir(exc, dest_dir):
    print('Error when trying to create DIR:', dest_dir)
    print(exc)
    print()

def error_on_file(exc, src_path):
    print('Error when trying to copy FILE:', src_path)
    print(exc)
    print()

def copydir(source, dest, indent = 0):
    """Copy a directory structure overwriting existing files"""
    for root, dirs, files in os.walk(source):
        if not os.path.isdir(root):
            os.makedirs(root)
        for each_file in files:
            rel_path = root.replace(source, '').lstrip(os.sep)
            dest_dir = os.path.join(dest, rel_path)
            dest_path = os.path.join(dest_dir, each_file)

            try:
                os.makedirs(dest_dir)
            except OSError as exc:
                if 'file exists' not in str(exc).lower():
                    error_on_dir(exc, dest_dir)

            src_path = os.path.join(root, each_file)
            try:
                shutil.copyfile(src_path, dest_path)
            except Exception as exc:
                # here you could take an appropriate action
                # rename, or delete...
                # Currently, script PRINTS information about such files
                error_on_file(exc, src_path)


if __name__ == '__main__':
    arg = sys.argv
    if len(arg) != 3:
        print('USAGE: python copy.py SOURCE DESTINATION')
    copydir(arg[1], arg[2])
  • rsync is a great tool but your answer doesn't address the Filename too long error we are told is reported during a copy. – roaima Apr 16 '17 at 21:09
  • You might at least remove the parts that aren't relevant to the situation you're answering, instead of directly copy-pasting the answer – ilkkachu Apr 16 '17 at 21:17
  • @roaima, ok, you are right. But it would be better to point, that the answer is not appropriate, bcz the problem is filesystem limitations, and rsync doesn't solve them. Anyway, thanks for your comment;) – maxkoryukov Apr 16 '17 at 21:51
  • @ilkkachu it would be better to mention which options are not relevant, than just complain in comments. I tried to help, I found that robocopy solves such problem on Win, and rsync - is a good alternative for robocopy , I used rsync for data-backup, but not so often, to know all its options. If you know how - share your knowledge;) – maxkoryukov Apr 16 '17 at 21:54
  • 1
    Rsync worked perfectly and didn't have the same issue as the terminal "copy" nor my file managers way of copying files where it spit out errors on files with long names. – raxidopegi Apr 17 '17 at 9:49

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