2016-12-14 143 views
0

想一個腳本來從我的內部從目錄中的文件夾移動到外部硬盤....如何從shell腳本中移動目錄中的目錄?

#!/bin/bash 
for i in *; do 
    if [[ $i == [* ]]; then 
     mv $i /entertainment/movies/; 
    fi 
done 

我得到下面的錯誤:

mv: cannot stat 'DVDRip': No such file or directory 
mv: cannot stat '-': No such file or directory 
mv: cannot stat 'x264': No such file or directory 
mv: cannot stat '-': No such file or directory 
mv: cannot stat 'DD5.1': No such file or directory 
mv: cannot stat '-': No such file or directory 
mv: cannot stat '1GB': No such file or directory 
mv: cannot stat '-': No such file or directory 
mv: cannot stat 'ESub': No such file or directory 
+2

添加引號包圍'$ i':'「$ I」' –

+0

它的伎倆......的「MV」正在執行......應該已經添加了詳細確認它快一點.. .. – coolstoner

回答

0

使用雙引號變量擴展確保空白處理正確。

mv "$i" /entertainment/movies/ 

if測試可以,如果你只遍歷文件你有興趣可以省略。

for i in [*; do 
    mv $i /entertainment/movies/ 
done 

然後你甚至可以拋棄的循環。

mv [* /entertainment/movies/