3

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?

Derviş Kayımbaşıoğlu
  • 28,492
  • 4
  • 50
  • 72
john doe
  • 53
  • 5
  • [du -b -h /opt/splunk/var/run](https://www.opennet.ru/man.shtml?topic=du&category=1&russian=2) ? – Victor Gubin Jan 10 '19 at 20:44
  • Stack Overflow is a site for programming and development questions. You should probably use another site on the [Stack Exchange network](https://stackexchange.com/sites) for this question. If you feel the question is on-topic, then see [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). It should be easy to find an example on the web. This question has been asked and answered many times. – jww Jan 11 '19 at 03:39

3 Answers3

2

try du. here is the example

du -sh *.bundl *.delta

for the total

du -sch *.bundl *.delta | grep total
Derviş Kayımbaşıoğlu
  • 28,492
  • 4
  • 50
  • 72
2

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 }'

zinovyev
  • 2,084
  • 1
  • 22
  • 32
  • when i do ur command it is giving the erro -- you have too many ')' moreover find is also searching files named bundle inside Splunk directory also ( from my above example) – john doe Jan 10 '19 at 21:20
  • I mean if u see my example , there is a directory called splunk inside the run.Splunk directory also have some files which contain bundle in their name.find command is listing out them also.I dont want it to go deeper than run directory .It should only consider the files whose name contain bundle or delta under run directory and give me total disk usage. – john doe Jan 10 '19 at 21:23
  • 1. I've fixed the path so it will use the correct folder from now. 2. Try the command with `-regex` instead of the `-name` option. It may be a problem with `(` in your shell. – zinovyev Jan 10 '19 at 21:25
  • Still it goes inside splunk directory – john doe Jan 10 '19 at 21:29
  • You can use `-maxdepth 1` option of the find comand to limit the depth. So it will look like `find /opt/splunk/var/run -maxdepth 1 -regex '.*\(bundle\|delta\).*' -print0 | du -ch --files0-from=- | grep total | awk '{ print $1 }'` – zinovyev Jan 10 '19 at 21:30
  • find /opt/splunk/var/run -maxdepth 1 -regex '.*\(bundle\|delta\).*' -print0 , until here it works fine.if i use the total thing , it says permission denied.because these direcorty is owned by splunk user.i cannot change to splunk user.i can only do sudo -u splunk before find.i think not changing to splunk user is the problem here. – john doe Jan 10 '19 at 21:35
  • I checked with my friend who have root password , ur command works awesome. but is there any way we can change ur command for my situiation?? – john doe Jan 10 '19 at 21:45
0

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