I want to write a script that fills a directory with music until there’s a certain amount of space left. The directory may be on various partitions and I don’t know how to ask a directory for free space or it’s partition.
pseudocode
fill(directory)
until < 100 mb of free space in directory
copy music to directory
How would you do it using unix tools like bash, find, etc.
I assume you mean you have a specific directory, on a specific partition that you wish to fill until there is only 100 MB left.
The df command will return the amount of disk space left on a given directory’s disk/partition.
The fourth column will give free space
you can use awk to gain the fourth column value and ignore the headers. So your script will be something like: