简体   繁体   English

当在带有find的管道中使用时,`du`获取当前目录

[英]`du` takes current directory when using in pipe with find

I'm using a script in which I look for a file in a directory (and all of its subdirectories) and print the file + file's size. 我正在使用一个脚本,在该脚本中,我在目录(及其所有子目录)中查找文件,并打印文件+文件的大小。

It is like this : 就像这样:

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

(with the inputs $folder=folder_1 and $file=f1 The problem is that my output is (使用输入$folder=folder_1$file=f1的问题是我的输出是

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

Whereas the output of find $folder -name $file is only find $folder -name $file的输出仅为

folder_1/f1/file1
folder_1/file1

Why does it take my current directory, even if there is no file matching my search ? 即使没有与我的搜索匹配的文件,为什么也要使用当前目录?

尝试-exec选项:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM