Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/df
Get free disk space info from `df -kP`
https://github.com/sindresorhus/df
Last synced: about 2 months ago
JSON representation
Get free disk space info from `df -kP`
- Host: GitHub
- URL: https://github.com/sindresorhus/df
- Owner: sindresorhus
- License: mit
- Created: 2015-05-04T18:02:32.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2022-07-09T02:46:42.000Z (about 2 years ago)
- Last Synced: 2024-04-13T17:40:06.263Z (5 months ago)
- Language: JavaScript
- Size: 25.4 KB
- Stars: 64
- Watchers: 8
- Forks: 12
- Open Issues: 3
-
Metadata Files:
- Readme: readme.md
- Funding: .github/funding.yml
- License: license
- Security: .github/security.md
Awesome Lists containing this project
README
# df
> Get free disk space info from [`df -kP`](https://en.wikipedia.org/wiki/Df_\(Unix\))
Works on any Unix-based system like macOS and Linux.
*Created because all the other `df` wrappers are terrible. This one uses simple and explicit parsing. Uses `execFile` rather than `exec`. Ensures better platform portability by using the `-P` flag. Returns sizes in bytes instead of kilobytes and the capacity as a float.*
## Install
```sh
npm install @sindresorhus/df
```## Usage
```js
import {
diskSpace,
diskSpaceForFilesystem,
diskSpaceForFilesystemOwningPath
} from '@sindresorhus/df';console.log(await diskSpace());
/*
[
{
filesystem: '/dev/disk1',
type: 'ext4',
size: 499046809600,
used: 443222245376,
available: 55562420224,
capacity: 0.89,
mountpoint: '/'
},
…
]
*/console.log(await diskSpaceForFilesystem('/dev/disk1'));
/*
{
filesystem: '/dev/disk1',
…
}
*/console.log(await diskSpaceForFilesystemOwningPath('.'));
/*
{
filesystem: '/dev/disk1',
…
}
*/
```## API
### diskSpace()
Returns a `Promise` with a list of space info objects for each filesystem.
### diskSpaceForFilesystem(path)
Returns a `Promise` with the space info for the given filesystem path.
- `filesystem` - Name of the filesystem.
- `type` - Type of the filesystem. *(Not available on macOS)*
- `size` - Total size in bytes.
- `used` - Used size in bytes.
- `available` - Available size in bytes.
- `capacity` - Capacity as a float from `0` to `1`.
- `mountpoint` - Disk mount location.#### path
Type: `string`
A path to a [filesystem device file](https://en.wikipedia.org/wiki/Device_file). Example: `'/dev/disk1'`.
### diskSpaceForFilesystemOwningPath(path)
Returns a `Promise` with the space info for the filesystem the given path is part of.
#### path
Type: `string`
A path to a file/directory on the filesystem to get the space info for.