Question
In some case, you may need to know the size of free disk space. Then you can leverage the function below which leverage command df.
Sample Code
Below sample code will return the size in GB of free disk space.
This function
freespace take one argument and show the free disk space of the given path.
Usage Example
The command df can show the below output to indicate the free disk space format:
If you want to show the disk space in GB with the 'G', leveraging the argument -B, --block-size=SIZE (scale sizes by SIZE before printing them)
Then you want to filter out the line containing the size of free disk space and get rid of the title, try this:
Finally, we just use command awk to retrieve the target field:
In some case, you may need to know the size of free disk space. Then you can leverage the function below which leverage command df.
Sample Code
Below sample code will return the size in GB of free disk space.
- freespace()
- {
- df --block-size=1G -P $1 | grep -vE '^Filesystem|tmpfs|cdrom|Available' | awk '{ print $4 }'
- }
Usage Example
The command df can show the below output to indicate the free disk space format:
If you want to show the disk space in GB with the 'G', leveraging the argument -B, --block-size=SIZE (scale sizes by SIZE before printing them)
Then you want to filter out the line containing the size of free disk space and get rid of the title, try this:
Finally, we just use command awk to retrieve the target field:
沒有留言:
張貼留言