Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
909 views
in Technique[技术] by (71.8m points)

bash - How to get total size of folders with find and du?

I'm trying to get the size of the directories named "bak" with find and du.

I do that : find -name bak -type d -exec du -ch '{}' ;

But it returns the size for each folder named "bak" not the total.

Anyway to get them ? Thanks :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use xargs(1) instead of -exec:

find . -name bak -type d | xargs du -ch

-exec executes the command for each file found (check the find(1) documentation). Piping to xargs lets you aggregate those filenames and only run du once. You could also do:

find -name bak -type d -exec du -ch '{}' ; +

If your version of find supports it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...