민서네집

디렉터리 합치기 (Merge Directory) 본문

LINUX

디렉터리 합치기 (Merge Directory)

브라이언7 2016. 5. 16. 14:48

mv 명령으로 이동하면 동일한 파티션 내에서는 실제 Copy가 이루어지지 않기 때문에 매우 빠르게 이동이 이루어진다.


그런데 합치려는 폴더가 이미 생성되어 있는 경우는 mv 명령이 에러를 내면서 실행이 안되는데... 


이런 경우 Windows 운영체제는 Merge가 매우 쉽게 되는데, (합치겠냐고 물어보고, 사용자는 단순히 예 버튼만 눌러주면 된다.) Linux 운영체제에서는 어떻게 하면 될까?


rsync -aplx --link-dest=dir1/ dir1/ merged/
rsync -aplx --link-dest=dir2/ dir2/ merged/

This would create hardlinks rather than moving them, you can verify that they were moved correctly, then, remove dir1/ and dir2/


[출처] http://serverfault.com/questions/155989/merge-2-directory-trees-in-linux-without-copying


rsync 파일을 이용해서 Copy 하고, 삭제하는 방법


rsync --remove-source-files --progress SRC [SRC]... DEST


find -type d -empty -delete


☞ 현재 디렉터리 이하의 빈 디렉터리가 모두 삭제됨.


[출처] http://unix.stackexchange.com/questions/127712/merging-folders-with-mv


--remove-source-files 대신에 --delete-after 옵션을 붙이면 rsync로 파일이 전송된 후에도 파일이 삭제되지 않음. 도대체 이 옵션은 뭐하는 옵션?


http://superuser.com/questions/156664/what-are-the-differences-between-the-rsync-delete-options


'LINUX' 카테고리의 다른 글

리눅스 tee, 화면과 파일에 동시 출력하기 / screen / nohup  (0) 2016.08.12
Ubuntu Linux에 Redis 설치 완료  (0) 2016.08.12
Samba 설정  (0) 2016.05.03
smb.conf - domain master 설정  (0) 2016.05.03
User 의 Group 추가 / 제거  (0) 2016.05.03
Comments