긴 이름의 파일 복사

긴 이름의 파일 복사

저는 Linux 우분투 16을 사용하고 있으며 HDD에서 SSD로 약 400GB(약 100,000개의 파일)의 데이터를 복사해야 합니다. 해당 파일 중 약 1000개에 "이름이 너무 길고" 파일을 찾는 데 시간이 오래 걸리기 때문에 건너뛸 수 없기 때문에 이 작업을 수행할 수 없습니다. 이름이 긴 파일을 복사하는 프로그램이 있나요?

답변1

원래의 (잘못된) 답변

멋진 사람들은 그것이 rsync매력처럼 작용한다고 말했습니다.

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

원래 답변:https://superuser.com/a/29437/483428

UPD: 스크립트 포함

rsync좋아, 다른 멋진 사람들은 그게 해결책이 아니라고 했어 .파일 시스템 자체는 긴 이름을 지원하지 않습니다. 나는 신이 만든 형이상학적인 낮은 수준의 초비밀 도구가 아니라는 점에 주목하겠습니다. rsync(Windows용 도구는 많이 있습니다. btw;)

SRC따라서 여기에 모든 파일을 에서 로 복사 DST하고 파일 이름을 인쇄하여 오류(긴 이름 포함)를 발생시키는 짧은 Python 스크립트(Python 2.7은 Ubuntu에 기본적으로 설치되어 있음)가 있습니다.

  1. 다른 이름으로 저장copy.py
  2. 용법: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])

관련 정보