2012-12-21 121 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

-maxdepth 1添加到您的find命令中,以便它不會進入子目錄。

find手冊頁:

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

,它應該補充? –

+0

我的查找命令應該找到-maxdepth 1「$ soure」-type f -mtime「 - $ days」-exec mv {}「$ destination」\; 什麼? –

+0

not working給出以下錯誤find:warning:在非選項參數-type後指定了-maxdepth選項,但選項不是位置的(-maxdepth會影響在它之前指定的測試以及在它之後指定的測試)。請在其他參數前指定選項。 –