[英]Bash Script for printing the modified files in Summary and Verbose mode?
到目前為止,這是我的代碼。 我使用“ find”和mtime來遞歸地找到已修改文件的列表。
baseFile=$1;
mtime=$2;
outputmode=$3;
if [ $outputmode = 1 ]
then
find $1/ -type f -mtime $2 | ls -lh
fi
if [ $outputmode = 2 ]
then
echo $USER
find $1/ -type f -mtime $2 | wc -l
fi
該程序在執行期間接受輸入。 語法是./filename.sh param1 param2 param3
param1-必須在其中找到已修改文件的目錄的路徑。
“ mtime”參數的param2-值
param3接受2個值
值1輸出應該是這樣的(摘要模式)
Owner Number of files changes
sh 3
值2 out應該是這樣的(詳細模式)
sh
w------- 1 sh sh 1998 Feb 8 20:30 a.m
-rw-rw-r-- 1 sh sh 45000 Feb 8 20:29 a.txt
-rw-rw-r-- 1 sh sh 45000 Feb 8 20:29 b.txt
$ 1用於參數1,$ 2用於參數2。
摘要模式和詳細模式基於$ 3指示的第三個參數
我的代碼僅顯示修改后的文件以及該特定目錄中文件的總數。 至於詳細模式,我的代碼只打印目錄,但我只需要打印修改后的文件,對此將有任何幫助。
ls
從其參數列表而不是標准輸入中獲取文件名參數。 您可以使用xargs
將標准輸入轉換為參數
find "$baseFile"/ -type f -mtime "$mtime" -print0 | xargs -0 ls -lh
-print0
和-0
選項一起使用,以確保即使文件名帶有空格(也可以將它們視為多個參數)也可以正常工作。
或者,您可以只使用-exec
選項:
find "$baseFile"/ -type f -mtime "$mtime" -exec ls -lh {} +
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.