Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

space-hogs: cli for discovering surprisingly large directories #59

Closed
dylang opened this issue Feb 10, 2016 · 16 comments
Closed

space-hogs: cli for discovering surprisingly large directories #59

dylang opened this issue Feb 10, 2016 · 16 comments

Comments

@dylang
Copy link

dylang commented Feb 10, 2016

Example Situation

You'd like to quickly discover that a dependency in your node_modules is 45 MB larger than the rest, which are all a few KB. Or to just figure out why your HD is more full than you were expecting.

How the tool works

  1. Use du -sh or something like it to find the recursive size of each child directory.
  2. Compare the results. If any are significantly larger than the rest, drill into those dirs and repeat. Stop recursively drilling down when the individual sub directories are not of significant size.
  3. Output the paths and space used, and % overall, of the largest directories.

Example

my-project > space-hogs
45 MB  50%  node_modules/foo/node_modules/bar/bower_components
30 MB  48%  docs/videos/raw
 1 MB   2%  Everything Else

Similar Tools

  • WinDirStat - Windows only, GUI only, shows every directory, not just the largest offenders.
  • Grand Perspective - Mac only, GUI only, shows every directory, not just the largest offenders.
@forivall
Copy link

FYI: WinDirStat is based on KDirStat (-> QDirStat) (both designed for Linux, GUI only)

@ghost
Copy link

ghost commented Feb 10, 2016

If anyone is interested in this, I just threw a very basic version together in a gist. It recursively goes through the directories and lists the folders with their sizes. Folders that get drilled in deeper or are an endpoint will show in green.

(As example of some cmds)
https://gist.github.com/verth/053937d43c241ba5ba98

Example:

$ node index.js -vrh
240136 | ./assets/
330113 | ./node_modules/
1368502 | ./public/ **
-------------------
45061 | ./public/css/
1323441 | ./public/img/ **
-------------------

@sindresorhus
Copy link
Owner

👍 Looks useful. Someone make this! :)

https://github.com/sindresorhus/pretty-bytes could be useful for this.

@Qix-
Copy link
Collaborator

Qix- commented Feb 11, 2016

Something to think about - which directory do you report as being "big"? What constitutes as "big"? What's the margin?

Perhaps a tree-like output with sorted directories (by size) and the human-readable sizes would be super effective. Perhaps if I know a directory is going to be big - and that's okay - but there's other unaccounted-for space that's being taken up in another directory, I don't want that first directory being the only one shown.

Just a thought.

@ewnd9
Copy link

ewnd9 commented Feb 11, 2016

Take a look at ncdu (available at least on linux). Looking like exactly what you want

2016-02-11t13 53 30 824z

@Qix-
Copy link
Collaborator

Qix- commented Feb 11, 2016

brew install ncdu appears to work on OS X. I'll give it a try. Thanks @ewnd9 :)

For anyone wondering how to quit, :q (same as vi). VI navigation seems to work too.

@forivall
Copy link

And from a quick google search (not on windows rn), it appears to be available in cygwin and in msys

@sindresorhus
Copy link
Owner

@dthree Could it be beneficial to use vorpal here for interactivity?

@dthree
Copy link

dthree commented Feb 11, 2016

For sure! Would be pretty easy for something to throw something like ncdu together in Node.

@backspaces
Copy link

I like OmniDisksweeper: https://www.omnigroup.com/more (Mac only, alas)
.. but would love a cli for scripts, both local and on servers.

@addyosmani
Copy link

I wouldn't mind working on this unless someone else really wants to take it.

@dthree
Copy link

dthree commented Feb 28, 2016

👍 on Addy taking it!

@dylang
Copy link
Author

dylang commented Feb 28, 2016

I've started working on it @addyosmani, want to work together? I'll push what I have to Github today.

@dylang
Copy link
Author

dylang commented Feb 28, 2016

@sindresorhus @dthree @addyosmani and friends: here is my take on my own module request:

Install

$ npm i -g space-hogs

Usage

$ space-hogs --help

  Discover surprisingly large directories.

  Usage
    space-hogs [path] [size] [--depth=number]

  Options
    directory        Directory to scan. Defaults to the current directory.
    size             Minimum size in MB. Defaults to 6% of the total MB.
    --depth=number   Number of sub-directories to dive into. 0 = none. Defaults to all.

  Examples

    $ space-hogs
    $ space-hogs node_modules 5 --depth=0
    $ space-hogs 1000

Example

~/projects/npm $ space-hogs
151 MB ~/projects/npm
Largest children directories, each larger than 9 MB
├──  31 MB [▒   ] /.git
├──   9 MB [▒   ] /node_modules/npm-registry-couchapp/node_modules
├──  12 MB [▒   ] /node_modules/tap/node_modules/nyc/node_modules
├──  20 MB [▒   ] /node_modules/standard/node_modules/standard-engine/node_modules/eslint/node_modules
├──  17 MB [▒   ] /node_modules/standard/node_modules/standard-format/node_modules/esformatter-jsx/node_modules/babel-core/node_modules
└──  62 MB [▒▒  ] (everything else)
    151 MB Total

Contribute

https://github.com/dylang/space-hogs

@dylang
Copy link
Author

dylang commented Feb 29, 2016

If you tried space-hogs when I first posted it a 7 hours ago and it didn't work, try again. It now supports du implementations from both BSD (OS X's default) and GNU (such as brew install coreutils), and gets the same results with either.

$ npm i -g space-hogs

Thanks go to @backspaces for the quick bug report. 😄

@dylang
Copy link
Author

dylang commented Apr 3, 2016

I'm closing this as space-hogs is available to use.

Any further discussion can be created as an issue with space-hogs.

Thanks everyone for your ideas and suggestions, I hope the tool has been useful!

@dylang dylang closed this as completed Apr 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants