Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9035123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:40:49+00:00 2026-06-16T08:40:49+00:00

I have a variable called $driveusage that contains the following block of text: Filesystem

  • 0

I have a variable called $driveusage that contains the following block of text:

Filesystem     Type      Size  Used Avail Use% Mounted on
rootfs         rootfs    111G  8.7G   96G   9% /
/dev/sda1      ext3      111G  8.7G   96G   9% /
devtmpfs       devtmpfs   59M     0   59M   0% /dev
tmpfs          tmpfs      61M     0   61M   0% /dev/shm
tmpfs          tmpfs      61M  264K   60M   1% /run
tmpfs          tmpfs      61M     0   61M   0% /sys/fs/cgroup
tmpfs          tmpfs      61M   16K   61M   1% /tmp

I need to extract data from the rootfs line only, into separate variables (i.e. $drivesize, $driveused, $drivefree, not an array), just the size, used and avail numbers, and just the numbers only (including the decimal).
Keep in mind that the used value, once it goes over 9.9G, will appear as 10G (with no decimal point) and same when avail drops below 10G will appear as 9.9G.

I’ve tried every combination of preg_replace() but I’m just not good with those complex expressions. 🙁

Any help you could provide would be greatly appreciated 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T08:40:50+00:00Added an answer on June 16, 2026 at 8:40 am

    Here’s what I got:

    $df_info = explode(' ', shell_exec("df -H / | tail -1 | tr -s ' ' | cut -d ' ' -f 2,3,4"));
    $df = array(
        'size'      => $df_info[0],
        'used'      => $df_info[1],
        'available' => $df_info[2],
    );
    

    df -H / gets human-readable info about your disk, tail -1 gets the last line of that (the important figures, and tr -s ' ' | cut -d ' ' -f 2,3,4 gets the second, third, and fourth entries (“size”, “used”, and “avail”) in that row.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On my website I have a variable called $user_data that contains input from a
I have a PHP-variable called $go_Adress which contains the adress I need to get
I have a variable called value in my js that gets updated based on
I have a variable called path that is a url e.g. www.google.co.uk%3Fq%3Dde which i
I have a variable called $day_price that can hold one of two values -
I have variable called modifieddate of type DateTime, which can be set to null.
I have a variable called instdir that has the current directory. I need to
The scenario would be: you have a variable called person which contains a number
I have a variable called @field that is set to equal a field name,
I have a variable called direction that stores either: left , right . I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.