How to find the disk usage total of specific files in a directory

Viewed 389

So I have a directory

/opt/splunk/var/run/

So I want to get the disk usage of all the files under run directory which contains either world bundle or delta

Example :

ls -lrth /opt/splunk/var/run

6726763764-7937483-7237438.bundle (file)
ywueye-7274837-2829383.delta      (file)
serverclass.xml                   (file)
splunk                            (directory)

so I want the total disk usage of 6726763764-7937483-7237438.bundle and ywueye-7274837-2829383.delta files

is this possible?

3 Answers

try du. here is the example

du -sh *.bundl *.delta

for the total

du -sch *.bundl *.delta | grep total

You can try using find for a complex search and then count the total size with du command:


 find /opt/splunk/var/run \( -name "*bundle*" -o -name "*delta*" \) -print0 | du -ch --files0-from=-

or with regex for a shorter syntax:


find /opt/splunk/var/run -regex '.*\(bundle\|delta\).*' -print0 | du -ch --files0-from=-

Then you can use grep and awk to pick up only the total size from the output:


 find /opt/splunk/var/run -regex '.*\(bundle\|delta\).*' -print0 | du -ch --files0-from=- | grep total | awk '{ print $1 }'

use du command as below du -sh * |grep bundl

Related