16

Is there a command line tool which shows in real time how much space remains on my external hard drive?

Peter David Carter
  • 502
  • 2
  • 7
  • 29
oshirowanen
  • 2,571
  • 15
  • 46
  • 66
  • 2
    The answer depends on the file system. For example `df` can not show the correct values for btrfs (yet). Could you add this information to your question? – Jonas Stein May 03 '16 at 00:43

5 Answers5

33

As Julie said, you can use df to display free space, passing it either the mount point or the device name:

df --human-readable /home
df --human-readable /dev/sda1

You'll get something like this:

Filesystem Size  Used Avail Use% Mounted on
/dev/sda1  833G  84G  749G  10%  /home

To run it continuously, use watch. Default update interval is 2 seconds, but you can tweak that with --interval:

watch --interval=60 df --human-readable /dev/sda1
Alexander Batischev
  • 2,363
  • 11
  • 19
3

df is a simple command line utility that shows you disk usage, including free space.

Check man df for details.

Julie Pelletier
  • 7,562
  • 1
  • 20
  • 43
  • 1
    I currently use `df -h`, which gives me the required info as and when I type `df -h`. I was after something more live or real time, i.e. something which keeps updating the terminal automatically, so I don't have to type in a command to check. – oshirowanen May 02 '16 at 17:12
  • @oshirowanen You can use `watch`, and it will run it over and over and show you fresh output (normally every two seconds). Keep in mind that only one program can update the terminal at a time under normal conditions (i.e. if you don't want to make a complete mess of your screen), so if you want to do other things at the same time you need to dedicate a terminal to it or run it in something like screen, tmux, or dvtm to split the terminal into multiple virtual terminals. – Random832 May 02 '16 at 19:52
3

If you don't like the idea of dedicating a whole terminal to watching the output of df, you could consider a tool such as conky. There are countless examples of using conky to monitor everything from HDD usage, HDD temp, ram usage, local weather, news headlines... you name it.

sam
  • 22,265
  • 4
  • 22
  • 30
3

Just use the following:

watch -d df
Glorfindel
  • 805
  • 2
  • 10
  • 19
Karl
  • 29
  • 1
  • You should [edit] this answer to include an explanation of how this differs from the accepted answer - which already provides explanations on how to use the `df` and `watch` commands. – Anthony Geoghegan Jun 08 '18 at 08:57
0

Using the excellent answer provided above by Alexander Batischev, and this one by Ralf Friedl, I combined them with "sort" a la this link for this command:

watch -d -n 60 'df -H /dev/sd[a-z][0-9] | sort -r -k 5 -i'

That will let you watch all of your hard drives in a terminal, updated every minute, sorted by percentage of space used.

I don't know how much this answer may add to what is already here (this is my very first answer), but I thought I would put it here, in case someone comes looking for exactly what I wanted to do, which is how I ended up on this question in the first place. Thought I would try to save someone else the effort of having to figure out how to put "watch", "df" and "sort" together, if I could.

FYI, I used regex instead of just "/dev/sd*" because my system also shows several "udev" entries, which I didn't need or want to see. The command as written above hides those and only shows hard drives.