소스 파일 내의 모든 파일과 폴더를 대상 폴더로 (재귀 적으로) 이동해야하는 bash 스크립트에서 작업하고 있습니다. 가능한 한이 견고하게하고, 잠재적 인 argument list too long - errors를 해결하기 위해 노력하는find를 사용하여 xargs를 통해 파일을 이동하는 경우 "mv : can not stat"오류가 발생합니다.
, 나는 (움직임 함께 효율적으로 그룹) xargs
으로 파이프 find
명령을 (안전하게 이동 할 파일을 결정하는)를 사용하도록 선택했다. 공백이있는 잠재적 인 문제를 해결하기 위해 -print0
및 -0
도 사용하고 있습니다. 나는 다음과 같은 테스트 스크립트 작성했습니다
다음과 같이 몇 가지 이유로 보인다
#!/bin/bash
# create test source file structure, and destination folder
mkdir -p sourceDir/{subdir1,subdir\ with\ space\ 2}
mkdir -p destDir
touch sourceDir/subdir1/{a1.txt,noExtension1,file1\ with\ space.txt}
touch sourceDir/subdir\ with\ space\ 2/{a2.txt,noExtension2,file2\ with\ space.txt}
#move files/folders from source to destination
find sourceDir -mindepth 1 -print0 | xargs -0 mv --target-directory=destDir
이 작업 (파일이 이동 예) 하지만을 나는 수많은 오류를 얻을 :
mv: cannot stat `sourceDir/subdir with space 2/file2 with space.txt': No such file or directory
mv: cannot stat `sourceDir/subdir with space 2/noExtension2': No such file or directory
mv: cannot stat `sourceDir/subdir with space 2/a2.txt': No such file or directory
mv: cannot stat `sourceDir/subdir1/file1 with space.txt': No such file or directory
mv: cannot stat `sourceDir/subdir1/noExtension1': No such file or directory
mv: cannot stat `sourceDir/subdir1/a1.txt': No such file or directory
오류를 생성하지 않고 (내 스크립트에 표시된 소스 파일 용)이 작업을 수행 할 수 없습니까?
왜 파일과 폴더가 실제로 이동되기 때문에 이러한 오류가 생성되는 이유는 무엇입니까?
찾기 명령을 'find sourceDir -mindepth 1 -exec mv "{}"--target-directory = destDir \;로 바꾸십시오. –
위의 스크립트와 함께 사용하면 여전히 오류가 발생합니다. – Jonny