What is @sindresorhus/df?
@sindresorhus/df is an npm package that provides a simple way to get free disk space information for all mounted filesystems on a Unix-like operating system. It is a Node.js wrapper around the Unix `df` command.
What are @sindresorhus/df's main functionalities?
Get disk space information
This feature allows you to retrieve information about the disk space of all mounted filesystems. The code sample demonstrates how to use the package to get disk space information and log it to the console.
const df = require('@sindresorhus/df');
(async () => {
const diskSpace = await df();
console.log(diskSpace);
})();
Other packages similar to @sindresorhus/df
diskusage
The 'diskusage' package provides similar functionality by allowing you to get disk usage information for a specific path. Unlike @sindresorhus/df, which retrieves information for all mounted filesystems, 'diskusage' focuses on a single path.
check-disk-space
The 'check-disk-space' package is another alternative that provides disk space information for a specific path. It is cross-platform and works on both Unix-like systems and Windows, whereas @sindresorhus/df is Unix-specific.
node-disk-info
The 'node-disk-info' package offers comprehensive disk information, including filesystem type, mount point, and usage statistics. It supports multiple platforms, making it more versatile compared to @sindresorhus/df, which is Unix-specific.
df
Get free disk space info from df -kP
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
$ npm install @sindresorhus/df
Usage
const df = require('@sindresorhus/df');
(async () => {
console.log(await df());
console.log(await df.fs('/dev/disk1'));
console.log(await df.file(__dirname));
})();
API
df()
Returns a Promise<Object[]>
with a list of space info objects for each filesystem.
df.fs(path)
Returns a Promise<Object>
with the space info for the given filesystem path.
filesystem
- Name of the filesystem.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
Path to a filesystem device file. Example: '/dev/disk1'
.
df.file(path)
Returns a Promise<Object>
with the space info for the filesystem the given file is part of.
path
Type: string
Path to a file on the filesystem to get the space info for.
License
MIT © Sindre Sorhus