2014-12-22 3 views
0
/bin/mv /myhome/templocation/images/*.iso /storage/data/repository/ >/dev/null 2>&1 

에 전체 디렉토리 대신에 특정 파일을 이동/인 MyHome/templocation에서// 저장/데이터/respository에 이미지.이동 명령은 내가 iso 파일을 이동하려면이 명령을 기다리고있어 쉘 스크립트

그러나 보이는 것은 다릅니다. 스크립트가 끝나면 전체 이미지 폴더가 /storage/data/repository/으로 이동합니다.

예 : /storage/data/repository/images/*.iso ...하지만 어디에서 잘못된 건가 /storage/data/respository/*.iso/

에 .iso로 복사 할 수있는 스크립트를 원했다 .. ?? 이 셸 스크립트는 시스템 부팅 중에 실행되므로 디버깅 할 수 없습니다. 제안 사항.

이 동작은 CentOS6에서 볼 수 있습니다.

+3

당신은 한 줄의 코드를 보여,하지만 당신은 스크립트에 대해 이야기. 우리에게 보여줄 뭔가가 있습니까? –

+1

그냥 그 명령을 사용해보십시오; 나머지 스크립트는 사용하지 않습니다. –

+0

; 복사본을'/ storage/data/repository /'또는 하위 폴더에 저장 하시겠습니까? –

답변

0

"*"을 사용한 쉘 확장은 임의의 버그와 보안 허점을 야기 할 수 있습니다. 그것은 사용하는 것이 훨씬 안전합니다 :

find ... -exec mv {} dst; 

처럼 :

find -maxdepth 0 \   <-- do not enter subdirectories 
-type f \     <-- just files (not links, directories) 
-name "*.iso" \    <-- just *iso names 
/myhome/templocation/images/ <-- base dir 
-exec mv {} /storage/data/repository/ \; <-- {} will be replaced by each file found 
0
foreach file in(path/with/wildcards*) 
do 
    if [ $file -f ];    # if file 
    then 
    mv $file 'new/location$file' 
    else 
    continue      # if subdirectory 
    fi 
done 

echo finished. 
관련 문제