rsync-쉘 스크립트를 사용하여 모든 JPG / jpg 파일을 하나의 하드 드라이브에서 단일 디렉토리로 이동

데이비드

나는 어떤 방향을 찾고 있습니다-그것은 일종의 작동을 유발하지만 그렇지 않습니다.

로컬 하드 드라이브가 있고 모든 .JPG 및 .jpg 파일을 다른 로컬 하드 드라이브 단일 디렉토리에 복사하고 싶습니다 .

rsync 사용-내 생각 : (소스 하드 드라이브는 Windows 시스템입니다-파일 이름에는 공백이 있습니다)
-소스 하드 드라이브의 모든 디렉토리 목록을 가져와 텍스트 파일에 넣습니다
.-따옴표를 추가하기 위해 디렉토리 목록 텍스트 파일을 편집합니다. 각 디렉토리
-쉘 스크립트 루프를 사용하여 텍스트 파일의 각 행에서 rsync를 실행합니다.



명령 줄에서 rysnc를 사용하고 디렉토리를 개별적으로 복사하면 작동합니다.

rsync -r --include '*.jpg' --include '*.JPG' --exclude '*' --prune-empty-dirs /"media"/"tfrd"/"Disk06_01_M"/"Disk02_01_X"/"x_images and camera"/"vernon pics_other"/"office_PBWT4_YBP6D-7wmff_bpwg4_2vgby"/"office pro disk 2"/"BCM"/"Program Files"/"Microsoft Small Business"/"Business Contact Manager"/"SDKComponents"/"PPCRL"/ /home/tfrd/Desktop/filesync/rsync/dir2/  

셸 스크립트 사용-작동하지 않음-문제는 dir 변수 및 슬래시 또는 공백에 있습니다-무엇보다도 마지막 디렉토리 이전에 구문 분석을 시도하는 것 같습니다.

나는 $ IFS로 변형을 시도했다-이것이 파싱 문제가있는 곳이라고 생각하기 때문이다.


내 스크립트 :

#!/bin/bash
file="/home/tfrd/Desktop/filesync/rsync/test_data_01.txt"

while IFS=$'\n' read -r line
#while IFS= read -r line
#while read line
do

#try 01
#rsync  --include '*.jpg' --include '*.JPG' --exclude '*/*/.' $line /home/rsync/dir2

#try 02
#rsync  --include '*.jpg' --include '*.JPG' --exclude '/*/' $line /home/rsync/dir2

#try 03
#rsync  --include '*.jpg' --include '*.JPG' --exclude '*/*/' $line /home/rsync/dir2

#try 04
rsync --protect-args --include '*.jpg' --include '*.JPG' --exclude '*/*/.' --prune-empty-dirs $line /home/rsync/dir2

done <"$file"



내 테스트 데이터 : (txt 파일에 단 2 줄)

/"media"/"tfrd"/"Disk06_01_M"/"Disk02_01_X"/"x_images and camera"/"vernon pics_other"/"office_PBWT4_YBP6D-7wmff_bpwg4_2vgby"/"office pro disk 2"/"BCM"/"Program Files"/"Microsoft Small Business"/"Business Contact Manager"/"SDKComponents"/"PPCRL"/
/"media"/"tfrd"/"Disk06_01_M"/"Disk02_01_X"/"x_images and camera"/"vernon pics_other"/"office_PBWT4_YBP6D-7wmff_bpwg4_2vgby"/"office pro disk 2"/"SBA"/"program files"/"Microsoft Small Business"/"Office Accounting 2008"/"SDKComponents"/"PPCRL"/



결과 : (읽을 수 있도록 정리 됨)

tfrd@Beagle-Ubuntu:~/Desktop/filesync/rsync$ clear


tfrd@Beagle-Ubuntu:~/Desktop/filesync/rsync$ ./script.sh 
/media/tfrd/Disk06_01_M/Disk02_01_X/x_images and camera/vernon pics_other/office_PBWT4_YBP6D-7wmff_bpwg4_2vgby/office pro disk 2/BCM/Program Files/Microsoft Small Business/Business Contact Manager/SDKComponents/PPCRL

rsync: link_stat "/media/tfrd/Disk06_01_M/Disk02_01_X/x_images" failed: No such file or directory (2)
rsync: link_stat "/home/tfrd/Desktop/filesync/rsync/and" failed: No such file or directory (2)
rsync: change_dir "/home/tfrd/Desktop/filesync/rsync//camera" failed: No such file or directory (2)
rsync: change_dir "/home/tfrd/Desktop/filesync/rsync//pics_other/office_PBWT4_YBP6D-7wmff_bpwg4_2vgby" failed: No such file or directory (2)
rsync: link_stat "/home/tfrd/Desktop/filesync/rsync/pro" failed: No such file or directory (2)
rsync: link_stat "/home/tfrd/Desktop/filesync/rsync/disk" failed: No such file or directory (2)
rsync: change_dir "/home/tfrd/Desktop/filesync/rsync//2/BCM" failed: No such file or directory (2)
rsync: change_dir "/home/tfrd/Desktop/filesync/rsync//Files" failed: No such file or directory (2)
rsync: link_stat "/home/tfrd/Desktop/filesync/rsync/Small" failed: No such file or directory (2)
rsync: change_dir "/home/tfrd/Desktop/filesync/rsync//Business" failed: No such file or directory (2)
rsync: link_stat "/home/tfrd/Desktop/filesync/rsync/Contact" failed: No such file or directory (2)
rsync: change_dir "/home/tfrd/Desktop/filesync/rsync//Manager/SDKComponents" failed: No such file or directory (2)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1183) [sender=3.1.0]


/media/tfrd/Disk06_01_M/Disk02_01_X/x_images and camera/vernon pics_other/office_PBWT4_YBP6D-7wmff_bpwg4_2vgby/office pro disk 2/SBA/program files/Microsoft Small Business/Office Accounting 2008/SDKComponents/PPCRL

rsync: link_stat "/media/tfrd/Disk06_01_M/Disk02_01_X/x_images" failed: No such file or directory (2)
rsync: link_stat "/home/tfrd/Desktop/filesync/rsync/and" failed: No such file or directory (2)
rsync: change_dir "/home/tfrd/Desktop/filesync/rsync//camera" failed: No such file or directory (2)
rsync: change_dir "/home/tfrd/Desktop/filesync/rsync//pics_other/office_PBWT4_YBP6D-7wmff_bpwg4_2vgby" failed: No such file or directory (2)
rsync: link_stat "/home/tfrd/Desktop/filesync/rsync/pro" failed: No such file or directory (2)
rsync: link_stat "/home/tfrd/Desktop/filesync/rsync/disk" failed: No such file or directory (2)
rsync: change_dir "/home/tfrd/Desktop/filesync/rsync//2/SBA" failed: No such file or directory (2)
rsync: change_dir "/home/tfrd/Desktop/filesync/rsync//files" failed: No such file or directory (2)
rsync: link_stat "/home/tfrd/Desktop/filesync/rsync/Small" failed: No such file or directory (2)
rsync: change_dir "/home/tfrd/Desktop/filesync/rsync//Business" failed: No such file or directory (2)
rsync: link_stat "/home/tfrd/Desktop/filesync/rsync/Accounting" failed: No such file or directory (2)
rsync: change_dir "/home/tfrd/Desktop/filesync/rsync//2008/SDKComponents" failed: No such file or directory (2)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1183) [sender=3.1.0]
야노스

모든 단일 경로 요소를 인용 할 필요는 없습니다.

경로 목록이있는 텍스트 파일에서 따옴표를 사용하지 않고 파일 이름 만있는 것이 좋습니다.

/media/tfrd/Disk06_01_M/Disk02_01_X/x_images and camera/vernon pics_other/office_PBWT4_YBP6D-7wmff_bpwg4_2vgby/office pro disk 2/BCM/Program Files/Microsoft Small Business/Business Contact Manager/SDKComponents/PPCRL/
/media/tfrd/Disk06_01_M/Disk02_01_X/x_images and camera/vernon pics_other/office_PBWT4_YBP6D-7wmff_bpwg4_2vgby/office pro disk 2/SBA/program files/Microsoft Small Business/Office Accounting 2008/SDKComponents/PPCRL/

그리고 다음과 같이 스크립트를 작성합니다.

#!/bin/bash
file="/home/tfrd/Desktop/filesync/rsync/test_data_01.txt"

while IFS=$'\n' read -r line
do
    rsync --protect-args --include '*.jpg' --include '*.JPG' --exclude '*/*/.' --prune-empty-dirs "$line" /home/rsync/dir2
done < "$file"

그게 다야. 공지 사항 $line에 묶여 "..."의 경로 인수로 사용하는 경우 rsync. 이렇게하면 포함 된 공백 및 기타 특수 문자가 올바르게 처리됩니다. 내부의 전체 콘텐츠 "..."는 단일 값으로 처리되므로 작동합니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관