views:

729

answers:

4

1) I am in some directory 2) I want to find out how much free space is left there

Is there a simple command that does this? I don't want to look in fstab or whatever, having to map the devices & mount points in my mind in order to determine how much free space I have left.

+11  A: 

Try df -h

Better yet: df -h . or df -h path-to-file

João da Silva
A: 
df -Ph $PWD | tail -1 | awk '{ print $3}'
Quassnoi
+3  A: 

I'd use the following to be more compatible with all the different df(1) and their output:

df . | awk '$3 ~ /[0-9]+/ { print $4 }'

No need to use tail(1) becaus eof the regex matching.

Keltia
+4  A: 

The 'df' command others discuss is only half the equation. Knowing the file system has free space does not imply that the user has access to the space.

You can also use the command:

df -k .

To find out the free space on the current file system. 'df' is smart enough to walk the tree for you and report it. If you want to check quotas (see below) then you can process the output of df to find the file system to check the quota on.

There may be no free inodes (df -i $PWD), there could be reserved blocks for the super user (by default on ext2/3/4, 5% of the total is reserved for root). I believe df shows the free space including the reserved blocks, so the number you see is actually higher than is available if you're not root.

The user may have quota restrictions. Quota restrictions is far less common these days since the cost of storage is so low, but it's worth checking with the quota command too.

Adam Hawes