[SOLVED] Exec find command

Hey guys.

I’am trying to execute and show the output of following command :
find /var/log/openhab2/ -type f -name ‘.’ -exec du -ch {} + | grep totalt$
this command will show the complete size of logfiles.

but all i get is some text that explaines how to format the find command

If i execute the command from the console, then i get
29M totalt

I tried to configure through Paper UI and manually.
Manually i have this in my items file:
String logSize “Log-størrelse: [%s MB]” (System) {exec="<[find /var/log/openhab2/ -type f -name ‘.’ -exec du -ch {} + | grep totalt$]"}

I entered your command as it appears in your post and got no output. The following does (from the command line) what I think you are trying to do:

find /var/log/openhab2/ -type f -name '*.log*' -print0 | \
     du -ch --files0-from=- | \
     sed -n '$p'

@scottk thanks mate, but the result on my side is the same.

I solved my problem by putting this in a script file and executing that.

/usr/bin/find /var/log/openhab2/ -type f -name ‘*.log *’ -exec du -ch {} + | grep totalt | awk ‘{$NF="";sub(/[ \t]+$/,"")}1’ | sed ‘s/.$//’

Looks overly complicated for what you’re trying to do, furthermore that command won’t differentiate between ‘29K’ ‘29M’ or ‘29G’, why not use this to get the figure in kilobytes:

du -k /var/log/openhab2 | awk '{print $1}'


Thanks @Benjy that looks a lot more simpler.

What if i won’t that output in MB then?

GNU du has a -B option that allows you to have a human readable version of many units:

du -BM /var/log/openhab2 | awk '{print $1}' | sed 's/.$//'

Prints in Mebibytes (1024 * 1024 bytes) which is likely what you want!

du -BMB /var/log/openhab2 | awk '{print $1}' | sed 's/.$//'

Prints in Megabytes (1000 * 1000 bytes)

use du --help for more info, and for what’s supported in your system.

Thanks @Benjy that really help a lot.

1 Like