Jump to content

Ever wanted to know how much space you had free?


DOlson
 Share

Recommended Posts

Here is a simple script I wrote today while setting up my sisters' computer with Debian. What it does is checks the freespace on a given partition, tells how much is left, and what percentage is in use. It should be good enough for them. I know a few times I wanted something simple like this without opening a terminal (I have a commandline at the top of my screen, so it's easy to run a command) or without running a full-blown app like kdf.

 

Here's a screenshot:

dur.png

 

Here's the script:

#!/bin/sh

FREE=`df -h | grep hda3 | awk '{ print $4 }'`

USED=`df -h | grep hda3 | awk '{ print $5 }'`

zenity --info --text="You have $FREE free, $USED of your space is in use." --title="Disk Usage Report"

 

That script will show the space of partition hda3, so modify it to your own delight. :) You'll need zenity installed too.

Link to comment
Share on other sites

To my knowledge, there is no program called GDF, so I did this:

 

save that script as /usr/local/bin/gdf

chmod +x /usr/local/bin/gdf

 

Now I can just run it anytime by typing gdf.

 

I meant to write this script like a year ago, but yeah, here it is now. :)

Link to comment
Share on other sites

I just

vi fr6.sh >copy and pasted the script and saved >opened a terminal and ran fr6.sh, and it worked.

fr=free

6=hda6

 

Then I did the same for 2 other partitions, so I have a fr6.sh, fr8.sh, and fr9.sh Any idea how the make the script read and display more than one partition, and show the label?

Link to comment
Share on other sites

Any idea how the make the script read and display more than one partition, and show the label?

 

Sure:

 

#!/bin/sh



FREE1=`df -h | grep hda3 | awk '{ print $4 }'`

USED1=`df -h | grep hda3 | awk '{ print $5 }'`

NAME1=Home



FREE2=`df -h | grep hda1 | awk '{ print $4 }'`

USED2=`df -h | grep hda1 | awk '{ print $5 }'`

NAME2=Root



FREE3=`df -h | grep hdc2 | awk '{ print $4 }'`

USED3=`df -h | grep hdc2 | awk '{ print $5 }'`

NAME3=Backup



zenity --info --title="Disk Usage Report" --text="

You have $FREE1 free space on $NAME1, $USED1 is in use.n

You have $FREE2 free space on $NAME2, $USED2 is in use.n

You have $FREE3 free space on $NAME3, $USED3 is in use."

 

Now, just edit each thing how you want it, and you'll get a screenshot like this:

 

dur2.png

 

EDIT: I noticed just now that you mentioned a label... Well, as you can see, the script allows you to put anything you like as the label, but if you meant some other label, then I don't know. It can be done, but I don't see any labels in my output of df.

Link to comment
Share on other sites

I got it to work but despite of using the last script (with 3 spaces), when typing gdf.sh I got the disk usage report window but with a simple line reporting the 3 spaces information, like this:

 

You have 2.0G free space on Home, 61% is in use./nYou have 3.8G free space on Windows, 61&is in use./nYou have 2.3G free, ......

 

How to break it in 3 lines, as you've gotten, one line to each space? Could it be a typo?

Link to comment
Share on other sites

You have 2.0G free space on Home, 61% is in use./nYou have 3.8G free space on Windows, 61&is in use./nYou have 2.3G free, ......

 

Sorry Dolson, read instead /. I've just copied and paste your script to gedit.

It looks like yours.

zenity --info --title="Disk Usage Report" --text="

You have $FREE1 free space on $NAME1, $USED1 is in use. n

You have $FREE2 free space on $NAME2, $USED2 is in use. n

You have $FREE3 free space on $NAME3, $USED3 is in use."

Link to comment
Share on other sites

You copied and pasted my script, and it doesn't work? Why does it work for everyone else? Maybe you have an old version of zenity? I don't know... If the slashes were wrong, then that would have explained it.

Link to comment
Share on other sites

That is awesome. You can, of course, just use Gnome system monitor to get the same info...

 

Yes, and you can also use the df command. But that's not the point. Some people (ie: my sisters) might like to know how much space is free without knowing much about Linux... This is why I wrote this.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...