View previous topic :: View next topic |
Author |
Message |
flangemonkey n00b
Joined: 26 Jul 2010 Posts: 29
|
Posted: Sat May 18, 2013 12:09 pm Post subject: [Solved] Help with find - exec and du |
|
|
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 |
|
|
chithanh Developer
Joined: 05 Aug 2006 Posts: 2158 Location: Berlin, Germany
|
Posted: Sat May 18, 2013 2:10 pm Post subject: |
|
|
You need to pass {} as placeholder for the filename:
Code: | # find ... -exec du -ch {} \; |
|
|
Back to top |
|
|
khayyam Watchman
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Sat May 18, 2013 2:25 pm Post subject: |
|
|
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 |
|
|
flangemonkey n00b
Joined: 26 Jul 2010 Posts: 29
|
Posted: Sat May 18, 2013 6:58 pm Post subject: |
|
|
bah!
I should've noticed that!
thanks for your answers, hopefully they'll help other people too |
|
Back to top |
|
|
|