Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Solved] Help with find - exec and du
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
flangemonkey
n00b
n00b


Joined: 26 Jul 2010
Posts: 29

PostPosted: Sat May 18, 2013 12:09 pm    Post subject: [Solved] Help with find - exec and du Reply with quote

Hi,

I tried using du through find - exec and didn't get the results I expected:

Code:
# find /dir/ -iname '*searchterm*' -exec du -ch \; | grep total
1.1G    total
# du -ch /dir/subdir/searchterm_directory_match
20G     /dir/subdir/searchterm_directory_match
20G     total


What did I do wrong..? :)


Last edited by flangemonkey on Sat May 18, 2013 6:58 pm; edited 1 time in total
Back to top
View user's profile Send private message
chithanh
Developer
Developer


Joined: 05 Aug 2006
Posts: 2158
Location: Berlin, Germany

PostPosted: Sat May 18, 2013 2:10 pm    Post subject: Reply with quote

You need to pass {} as placeholder for the filename:
Code:
# find ... -exec du -ch {} \;
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Sat May 18, 2013 2:25 pm    Post subject: Reply with quote

flangemonkey ....

You need to pass the result of the find to exec ... so, for example:

Code:
% find /path -type d -exec du -ch '{}' \;

In the above your searching for a 'file' and then expecting the 'total' for the directory, so of course the results of the two commands are different. So, what is it you want, the directory size or the filesize? I ask as you can pass a pattern to du:

Code:
du -ch ~/path/*.txt

... but this doesn't provide the size of the directory, so, some idea of what specificly your after.

best ... khay
Back to top
View user's profile Send private message
flangemonkey
n00b
n00b


Joined: 26 Jul 2010
Posts: 29

PostPosted: Sat May 18, 2013 6:58 pm    Post subject: Reply with quote

bah!

I should've noticed that!

thanks for your answers, hopefully they'll help other people too :)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum