I wanted to get the freespace available from a given path. Currently, my method is by using
df -kb $PATH | awk 'NR == 2 {print $4}'.
The problem for the above method is it won’t work for a non-existing path.
So, it can be solved by mkdir -p $PATH.
But then again, it will create blank directories just to check for free spaces available (provided these path is not exist in the system earlier)
I can run rmdir $PATH after running my df, but remember? I use mkdir -p earlier and the OS may have created a few levels of directories and executing rmdir $PATH only manage to remove the last level.
So, any simple solution available just for me to check the free space from a given path(especially for nonexistent path)? or is there any utility that can output the mount point from a given directory path (so that I can just grep the mount path from df to get the available free spaces)?
If you want to know the space available for a director that you plan to create but does not exist yet, first you need to find the closest parent directory that exists:
then you can
dfon$existing_path. All this in a single bash function: