Byron / dua-cli

View disk space usage and delete unwanted data, fast.
https://lib.rs/crates/dua-cli
MIT License
4.19k stars 113 forks source link

Save and load? #137

Open lachesis opened 2 years ago

lachesis commented 2 years ago

Is there a way to save the scan result and reimport it for interactive view? This would be similar to ncdu's -o and -f options.

Byron commented 2 years ago

That would be interesting for some use-cases for sure and quite straightforward to implement I presume if one uses standard Rust serialization.

gosuwachu commented 11 months ago

@lachesis Can you describe your use case? It would help prfioritize this issue.

CouldBeThis commented 7 months ago

Not that anyone asked me but I do occasionally use pdu's --json-output and --json-input to save and load results. You can produce different visualizations for the same data.

My main simple use case is that I have a bunch of old spinning HDDs connected to a low resource computer. I added HDDs slowly over time as I needed space so there was no scheme of what files were where. Too chaosy. So it was required to learn how space was being used then plan a way to move things around.

It's kind of like using locate instead of find. locate periodically creates a database then lets you very quickly search through it, whereas find starts from scratch every time. If your file-set is relatively stable the speed can be an acceptable trade off.

And since it's json I guess you can do all kinds of things with it.

I think it would be cool if dua could do this because it's the one I like the best but tbh it is also acceptable to use the other available tools. As an intermediary, loading the jsons generated by pdu would be cool because dua does a much superior job of visualizing. But only once in a very long while with a very specific use case.

Byron commented 7 months ago

Definitely CC @piotrwach :).

piotrwach commented 7 months ago

I also have few use cases where having ability to load a file system walk from a file would be very useful:

  1. I work with remote machines where I don't want to run dua. I could instead run some shell command that would list all the files that I could then load in dua on my machine. E.g.
$ ssh remote_host find /home -ls > listing.txt
$ dua i --from-file listing.txt
  1. I sometimes need to analyse what is taking space in my Amazon S3 bucket. For that I would like to run something similar as in 1) e.g.
$ s3cmd ls --recursive "s3://mybucket/*" > listing.txt
$ dua i --from-file listing.txt

Unfortunately the formats of listing.txt in both cases are quite different:

find:

$ find . -ls
19692507        0 drwxr-xr-x    7 pwach            staff                 224  9 Nov 07:39 .
19692508        8 -rw-r--r--    1 pwach            staff                1000  9 Nov 07:39 ./1000bytes
19692511        0 drwxr-xr-x    3 pwach            staff                  96  9 Nov 07:39 ./empty-dir
19692512        0 -rw-r--r--    1 pwach            staff                   0  9 Nov 07:39 ./empty-dir/.gitkeep

vs

s3cmd

$ s3cmd ls --recursive "s3://mybucket/*"
2019-06-14 17:08         123  s3://mybucket/a/1.png
2019-06-15 17:08         456  s3://mybucket/b/2.png

For what it is worth, I have changed dua to achieve 2) already, but since it is not universal / probably a bit out of scope of this project I think we need more universal way of doing this.

ipstone commented 3 weeks ago

ncdu has the options to output/input indexed folders:

ncdu <options> <directory>

Options:
  -h,--help                  This help message
  -q                         Quiet mode, refresh interval 2 seconds
  -v,-V,--version            Print version
  -x                         Same filesystem
  -e                         Enable extended information
  -t NUM                     Number of threads to use
  -r                         Read only
  -o FILE                    Export scanned directory to FILE
  -f FILE                    Import scanned directory from FILE
  -0,-1,-2                   UI to use when scanning (0=none,2=full ncurses)
  --si                       Use base 10 (SI) prefixes instead of base 2
  --exclude PATTERN          Exclude files that match PATTERN
  -X, --exclude-from FILE    Exclude files that match any pattern in FILE
  -L, --follow-symlinks      Follow symbolic links (excluding directories)
  --exclude-caches           Exclude directories containing CACHEDIR.TAG
  --exclude-kernfs           Exclude Linux pseudo filesystems (procfs,sysfs,cgroup,...)
  --confirm-quit             Confirm quitting ncdu
  --color SCHEME             Set color scheme (off/dark/dark-bg)
  --ignore-config            Don't load config files

Refer to `man ncdu` for the full list of options.

which are quite handy for working/analyzing files on the remote server etc. - which are my use cases to manage large/complex folder/files. If dua can implement similar input/output format that will be terrific!

The format is a json format: https://dev.yorhel.nl/ncdu/jsonfmt