I am writing a bash script
to install a program for different users.
For that I want to make sure that each user has at least 500Mb
available in their $HOME
. My $HOME
directory looks as follows
jen@ser23:~$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 2,9G 1,1G 1,7G 40% /
udev 10M 0 10M 0% /dev
tmpfs 13G 826M 12G 7% /run
/dev/sda3 15G 9,8G 4,1G 71% /usr
tmpfs 32G 0 32G 0% /dev/shm
tmpfs 5,0M 0 5,0M 0% /run/lock
tmpfs 32G 0 32G 0% /sys/fs/cgroup
/dev/mapper/local_disk_1-tmp 3,7G 21M 3,7G 1% /tmp
/dev/mapper/local_disk_1-opt 20G 2,0G 18G 10% /opt
/dev/mapper/local_disk_1-project1 401G 287G 114G 72% /project1
/dev/mapper/local_disk_1-var 3,8G 1,7G 1,7G 50% /var
/dev/mapper/local_disk_1-project2 99G 70G 29G 71% /project2
/dev/mapper/local_disk_1-usr_local 2,0G 3,4M 1,9G 1% /usr/local
nfs4.sf0.ise.fhg.de:/g/6/TSB/Archiv 632T 349T 276T 56% /net/p/600/groupdrives/TSB/Archiv
nfs4.sf0.ise.fhg.de:/home 632T 349T 276T 56% /net/home
tmpfs 6,4G 0 6,4G 0% /run/user/12419
tmpfs 6,4G 4,0K 6,4G 1% /run/user/13471
tmpfs 6,4G 4,0K 6,4G 1% /run/user/9351
tmpfs 6,4G 0 6,4G 0% /run/user/13142
My idea is to use df -h /path/to/home | awk
but I am not sure how I can get the actual available space from df -h
. Any help please? Thanks, Jen.
jen@ser23:~$ df -P /net/home/j/jen
Filesystem 1024-blocks Used Available Capacity Mounted on
nfs4.sf0.dfd.fhg.de:/home 5242880 1026048 4216832 20% /net/home
The important point to remember is that
df
operates on filesystems, which may be attached to particular folders, and if you specify a path or file, it will resolve to usage of the filesystem on which file/folder resides. Sodf -P /net/home/j/jen
operates on the filesystem mounted at/net/home
, which isnfs4.sf0.ise.fhg.de
network attached storage apparently.The usage of a directory and all the files requires a recursive solution that will traverse files and directories within particular directory. The tool that you seek then, is
du
and in particulardu -shx /net/home/user
.Keypoints (for more read man du):
du
is recursive by default-s
provides summary instead of listing filesizes individually-h
provides human readable output. If you require further processing on data,-b
might be more preferable.-x
is to keepdu
descending into another. For instance, you could have another network server attached to/net/home/user/anotherplace
, so processing that directory is undesirable as it will give incorrect filesystem usage results.Considering that this is an assignment, further processing and manipulations on output of
du
are left to the reader to implementNo need to parse
df
output withawk
, you can use--output
switch:It looks like you're heading towards a workable solution already in the comments, but I'm going to throw this in:
I'd recommend not using -h because if the size is small enough, the G will turn to an M and your solution might break.