2017-04-06 52 views
0

我正在使用腳本在其中查找目錄(及其所有子目錄)中的文件並打印文件+文件的大小。`du`採用當前目錄在管道中使用時發現

它是這樣的:

find $folder -name $file | du --apparent-size 

(與輸入$folder=folder_1$file=f1 的問題是,我的輸出是

4 ./folder_1/f1 
8 ./folder_1 
13 . 

鑑於對find $folder -name $file的產量只有

folder_1/f1/file1 
folder_1/file1 

爲什麼它採取我當前的目錄,即使沒有匹配我的搜索的文件?

+0

如果你想使用'prune'開關,例如排除'abc'目錄只是一個'-path ./abc -prune -o'添加到您的找到命令 –

+0

在我的情況下,'file1'不在我的當前目錄中。但如果是這樣呢?我cannod排除該目錄。 – SnuKies

+0

抱歉,您的問題錯了。我認爲@vdavid提供瞭解決方案 –

回答

3

嘗試-exec選項:

find "$folder" -name "$file" -exec du --apparent-size '{}' \;