rsync로 중복 없이 파일 옮기기
rsync로 중복 제거, 원본 삭제하며 파일 옮기기
rsync는 파일 전송 및 동기화 툴이야. 특히 중복 건너뛰고 원본 삭제하며 옮길 때 유용해.
1. 중복 제거 & 원본 삭제 (Dry Run 먼저!)
rsync -avhn --ignore-existing --remove-source-files [원본] [대상]
-a: 아카이브 (권한/시간 보존),-v: 상세,-h: 읽기 쉬운 용량-n: Dry Run (실제 실행 안 함, 결과 예측)--ignore-existing: 대상에 파일 있으면 건너뛰기--remove-source-files: 성공 후 원본 삭제
2. 실제 실행: -n 옵션 제거
rsync -avh --ignore-existing --remove-source-files [원본] [대상]
3. 진행 상황 & 압축 전송
rsync -avzhP [원본] [대상]
-z: 압축 (네트워크 추천),-P: 진행률, 재개
여기서 배울 것
- rsync로 파일 전송 및 동기화하는 법을 안다.
- `--ignore-existing`으로 중복 파일을 건너뛰는 법을 안다.
- `--remove-source-files`로 원본 파일을 삭제하며 이동하는 법을 안다.
- `-n` (Dry Run)으로 안전하게 미리 확인하는 습관을 들인다.
원본 파일 보기 (.claude/skills/tn-transfer-unique-file-rsync/SKILL.md)
---
name: rsync를 이용한 파일 전송 및 동기화
description: This skill should be used when the user asks to transfer files between local or remote systems, synchronize directories, or move files with options like ignoring existing duplicates and removing source files using `rsync`.
version: 1.0.0
source: /home/son/prj/resume/backup_notes_260317/notion/Tech Note/tranfer unique file (rsync) 2f3d7efd824b803c8503e36539cf5ae0.md
---
# tranfer unique file (rsync)
1. check the file size
```bash
du -h --max-depth=1 [주소]
```
dry run
```bash
rsync -avhn --ignore-existing --remove-source-files [src] [target]
-a = archieve. permissions, timestamps, symbolic links, and subdirectories 다 보존
-v = Verbose (말많은). 이동하는 과정에서 로그를 띄울것
-h = Human-readable. 파일 사이즈를 GB등 읽기 편하게.
-n = Dry Run. 실제 수행 x, 결과 예측
--ignore-existing = 타겟 폴더에 파일이 있으면 아무것도 하지마라. (중복 제거)
--remove-source-files = 성공적으로 [target]폴더에 옮긴 뒤 [src] 폴더 파일을 지워라
ex)
rsync -avh --ignore-existing --remove-source-files /mnt/pool0_12tb/backup_released/Album_released/dreamdream/ /mnt/pool0_12tb/backup_released/dreamdream/
```
| **Flag** | **Meaning** | **Function in your command** |
| --- | --- | --- |
| **`-a`** | **Archive** | Preserves almost everything: permissions, timestamps, symbolic links, and subdirectories (recursive). It’s the "standard" way to copy folders safely. |
| **`-v`** | **Verbose** | Shows you a list of the files being processed in the terminal while the command runs. |
| **`-h`** | **Human-readable** | Formats numbers (like file sizes and transfer speeds) into units like **K**, **M**, or **G** so they are easier to read. |
| **`-n`** | **Dry Run** | **Very important.** It simulates the command without actually moving or deleting anything. It just tells you what *would* happen. |
| **`--ignore-existing`** | **Skip Existing** | Tells rsync: "If a file with the same name already exists in the target folder, **don't touch it.**" It effectively filters out the duplicates. |
| **`--remove-source-files`** | **Cleanup Source** | Tells rsync: "Delete the file from the [src] folder **only after** it has been successfully transferred to the [target]." |
1. remove n
2. remove original files
3.
`rsync -avzhP [소스폴더] [타겟폴더]`
- **`a` (archive):** 권한, 심볼릭 링크, 속성 등을 그대로 유지합니다. (가장 중요!)
- **`v` (verbose):** 어떤 파일이 복사되고 있는지 보여줍니다.
- **`z` (compress):** 데이터를 압축해서 전송합니다. (네트워크 전송 시 유용하지만, **로컬 하드 간 복사라면 오히려 CPU만 많이 쓰고 느려질 수 있으니 떼도 무방합니다.**)
- **`h` (human-readable):** 숫자를 GB, MB 단위로 읽기 쉽게 보여줍니다.
- **`P` (progress & partial):** **파일별 복사 퍼센트(%)와 남은 시간**을 실시간으로 보여줍니다. 혹시 중간에 끊겨도 이어서 할 수 있게 해줍니다.