How to find out the free disk space for a given path on a linux shell? [closed]
Asked Answered
R

4

20

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.

Rampageous answered 26/1, 2009 at 9:58 Comment(2)
duplicate: #230907Bathroom
This question is not a dupe of 230407, since it is specific to home directory. As one answer mentions, there could be a quota imposed on each user's home directory.Cum
B
46

Try df -h

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

Bosh answered 26/1, 2009 at 9:59 Comment(2)
df -h seems to work fine, but I can't df -h . or df -h path-to-file to work. For all 3 of those commands on my Amazon server, my output just looks like: Filesystem Size Used Avail Use% Mounted on /dev/xvda1 30G 21G 8.7G 71% /Annemarie
@Annemarie df returns the disk space usage. So it seems that you have only one partition (disk) on your server; namely /dev/xvda1. All your files are on this partition. So you get only the disk space usage of this partition for all files.Outsmart
E
16

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.

Eighty answered 26/1, 2009 at 10:38 Comment(0)
D
9

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.

Diallage answered 26/1, 2009 at 10:13 Comment(0)
E
2
df -Ph $PWD | tail -1 | awk '{ print $3}'
Encrust answered 26/1, 2009 at 10:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.