2012-12-21 4 views
2

원본 디렉토리에서 대상 디렉토리로 정의 된 옛날 파일을 이동시키는 다음 스크립트를 만들었습니다. 그것은 완벽하게 작동합니다.bash 스크립팅 개선

#!/bin/bash 

echo "Enter Your Source Directory" 
read soure 

echo "Enter Your Destination Directory" 
read destination 

echo "Enter Days" 
read days 



find "$soure" -type f -mtime "-$days" -exec mv {} "$destination" \; 

    echo "Files which were $days Days old moved from $soure to $destination" 

이 스크립트는 파일을 훌륭하게 이동하지만, 원하지 않는 파일을 원본 하위 디렉토리로 옮깁니다. 서브 디렉토리 파일을 가져 가면 안됩니다. 어떻게해야합니까?

답변

4

find 명령에 -maxdepth 1을 추가하면 하위 디렉토리로 이동하지 않습니다. find 사람 페이지에서

는 :

-maxdepth levels 
    Descend at most levels (a non-negative integer) levels of directories below the command line arguments. 
+0

이를 추가해야하는 위치? –

+0

내 find 명령은 -maxdepth 1 "$ soure"-type f -mtime "- $ days"-exec mv {} "$ destination"\을 찾아야합니다. 또는 뭔가 ???? –

+0

다음과 같은 오류가 발생합니다 : 경고 : 옵션이 아닌 인수 -type 뒤에 -maxdepth 옵션을 지정했지만 옵션이 위치하지 않습니다 (-maxdepth는 그 전에 지정된 테스트와 그 이후에 지정된 테스트에 영향을줍니다). 다른 인수 앞에 옵션을 지정하십시오. –