GithubHelp home page GithubHelp logo

df's Introduction

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

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<object[]> with a list of space info objects for each filesystem.

diskSpaceForFilesystem(path)

Returns a Promise<object> 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. Example: '/dev/disk1'.

diskSpaceForFilesystemOwningPath(path)

Returns a Promise<object> 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.

df's People

Contributors

bendingbender avatar gramakri avatar kevva avatar medusalix avatar richienb avatar sindresorhus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

df's Issues

doesnt work with sinopia

apparently it doesnt work with sinopia, because of some bug with scoped modules, its not clear is it a bug with npm or sinopia also. rlidwka/sinopia#278.

its basically a problem because of trash, and because sinopia is most popular and easy way to have private registry.

Parse File system type

Would be great if we can get the filesystem type from the output as well. We can get this by passing the -T option.

Volume names that end with a number are truncated

Issuehunt badges

Thanks for your work on execa and df!

Your regex to split df fails under the following conditions:

  • when volume names end with a number, the number is removed (so /Volumes/Untitled 123 is reported as /Volumes/Untitled). Note that on mac, when you format a new drive into multiple partitions, these are the default names, so this isn't an edge case.
  • if a device name has whitespace followed by a number, all the fields are off-by-one. This case should be much less common than the first case.

IssueHunt Summary

[
<
i
m
g

s
r
c

'
h
t
t
p
s
:
/
/
a
v
a
t
a
r
s
2
.
g
i
t
h
u
b
u
s
e
r
c
o
n
t
e
n
t
.
c
o
m
/
u
/
8
1
2
4
8
9
8
?
v

4
'

a
l
t

'
m
e
d
u
s
a
l
i
x
'

w
i
d
t
h

2
4

h
e
i
g
h
t

2
4

m
e
d
u
s
a
l
i
x
]
(
h
t
t
p
s
:
/
/
i
s
s
u
e
h
u
n
t
.
i
o
/
u
/
m
e
d
u
s
a
l
i
x
)

h
a
s

b
e
e
n

r
e
w
a
r
d
e
d
.

Backers (Total: $40.00)

Submitted pull Requests


Tips


IssueHunt has been backed by the following sponsors. Become a sponsor

Incorrect size

df output:

$ df --version
df (GNU coreutils) 8.30
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Torbjorn Granlund, David MacKenzie, and Paul Eggert.
$ df -kP /run/xo-server/mounts/cbb36e4c-3353-4126-8588-18ba25697403
Filesystem                  1024-blocks  Used    Available Capacity Mounted on
xx.xxx.xxx.xx:/xxxxxxxxxxx 198640150528 43008 198640107520       1% /run/xo-server/mounts/cbb36e4c-3353-4126-8588-18ba25697403

This module result:

{
  filesystem: '10.190.111.25:/backupdrive 1',
  size: 101007514140672,
  used: 44040192,
  available: 203407470100480,
  capacity: 0.01,
  mountpoint: '/run/xo-server/mounts/cbb36e4c-3353-4126-8588-18ba25697403'
}

Dump boundaries: [ 28, 11, 6, 13, 9, -1 ]

Dump cl:

[
  '10.190.111.25:/backupdrive 1',
  '98640150528',
  '43008',
  '198640107520',
  '1%',
  '/run/xo-server/mounts/cbb36e4c-3353-4126-8588-18ba25697403'
]

The size field appears to be missing the first character.

Probably build issue when building on travis CI

This is the screenshot that led me here :-

image

The build can be found here

It is mentioned that the package causing an issue is a dependency of mount-point. So, I believe the problem is with mount-point which declares @sindresorhus/df as a dependency.

I am using xdg-basedir and trash packages, due to which these packages enter the dependency tree.

Is this problem because of the presence of @ in the package name?

Weirdly enough, the same build worked fine on Node 0.11 and Node 0.12.
Link to Node 0.11 build
Link to Node 0.12 build

Columns incorrectly detected

Running on node16 + alpine3.14:

df output:

/root # df -kP /data0
Filesystem           1024-blocks    Used Available Capacity Mounted on
//10.0.1.100/data0   59979045276 50147765800 9831279476  84% /data0

Module output:

> require('@sindresorhus/df').file('/data0').then(console.log)
> {
  filesystem: '//10.0.1.100/data0',
  size: 61418542362624,
  used: 5135130624,
  available: 5939200,
  capacity: 794.76,
  mountpoint: '% /data0'
}

df info:

/root # df --version
df: unrecognized option: version
BusyBox v1.33.1 () multi-call binary.

Usage: df [-PkmhTai] [-B SIZE] [FILESYSTEM]...

Print filesystem usage statistics

        -P      POSIX output format
        -k      1024-byte blocks (default)
        -m      1M-byte blocks
        -h      Human readable (e.g. 1K 243M 2G)
        -T      Print filesystem type
        -a      Show all filesystems
        -i      Inodes
        -B SIZE Blocksize

Let me know if there's anything else I can provide

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.