3

In a shell script, I'm looking for a way to pass the du (disk usage) result to a numeric variable, so that I cantie the execution of a shell script to the size of a specific folder. I've tried something like size=$(du -sh /folder) but this passes an alphanumeric value to the variable 'size', plus the name of the folder, which is obviously not what I want.

I'm using OSX, but I believe this is more of a bash/linux question. Has anybody an idea on how to achieve that? Thank you very much.

5

size=$(du -s xxx | awk '{print $1}') will give the disk usage in kB. To get real used bytes use du -sb --apparent-size xxx. See man du for details.

| improve this answer | |
  • Awesome, exactly what I needed. Thanks a lot Marki. – brunobhr Feb 22 '16 at 23:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.