hackerNuB
hackerNuB

Reputation: 13

How to use exec and du command to find out size of files

I'm trying to create a script with the find command to find all directories with the name "bin" within the "/usr/" directory. I also want to know the size of each of these catalogues. How would I do this by using the -exec flag and du command?

This is what I've managed to scrape together so far:

find /usr/ -name "bin" -exec 

du bin

Upvotes: 0

Views: 1287

Answers (2)

neau
neau

Reputation: 48

The following oneliner outputs the directories and their total file sizes. The -c argument produces the grand total of the files inside.

$ find /usr -type d -name bin -exec du -shc {} +;

104K    /usr/src/gcc/contrib/reghunt/bin
67M /usr/bin
8.4M    /usr/local/bin
75M total

Upvotes: 2

nullPointer
nullPointer

Reputation: 4574

find /usr -type d -name "bin" -exec du {} \;

Upvotes: 3

Related Questions