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

Can 'erd' offer a 'du'-replacement features for '--summarize', '--block-size' and pipeline-able stdout? #182

Open
johnnyutahh opened this issue May 26, 2023 · 8 comments

Comments

@johnnyutahh
Copy link

johnnyutahh commented May 26, 2023

Might features similar to du's -s, -h, -B, -m be available, now or in the future?

These du features are remarkably valuable to me. Could be pretty neato to include in erdtree, maybe... if feasible? Maybe y'all are already handling/thinking about this?

(I did not see anything after a quick, lazy look through erd --help and https://github.com/solidiquis/erdtree README ... apologies if I missed something already documented.)

Here's my du's info/help/version, for potentially-handy reference:

$ du --version | ag core
du (GNU coreutils) 9.3
$
$ du --help
Usage: du [OPTION]... [FILE]...
  or:  du [OPTION]... --files0-from=F
Summarize device usage of the set of FILEs, recursively for directories.

Mandatory arguments to long options are mandatory for short options too.
  -0, --null            end each output line with NUL, not newline
  -a, --all             write counts for all files, not just directories
      --apparent-size   print apparent sizes rather than device usage; although
                          the apparent size is usually smaller, it may be
                          larger due to holes in ('sparse') files, internal
                          fragmentation, indirect blocks, and the like
  -B, --block-size=SIZE  scale sizes by SIZE before printing them; e.g.,
                           '-BM' prints sizes in units of 1,048,576 bytes;
                           see SIZE format below
  -b, --bytes           equivalent to '--apparent-size --block-size=1'
  -c, --total           produce a grand total
  -D, --dereference-args  dereference only symlinks that are listed on the
                          command line
  -d, --max-depth=N     print the total for a directory (or file, with --all)
                          only if it is N or fewer levels below the command
                          line argument;  --max-depth=0 is the same as
                          --summarize
      --files0-from=F   summarize device usage of the
                          NUL-terminated file names specified in file F;
                          if F is -, then read names from standard input
  -H                    equivalent to --dereference-args (-D)
  -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)
      --inodes          list inode usage information instead of block usage
  -k                    like --block-size=1K
  -L, --dereference     dereference all symbolic links
  -l, --count-links     count sizes many times if hard linked
  -m                    like --block-size=1M
  -P, --no-dereference  don't follow any symbolic links (this is the default)
  -S, --separate-dirs   for directories do not include size of subdirectories
      --si              like -h, but use powers of 1000 not 1024
  -s, --summarize       display only a total for each argument
  -t, --threshold=SIZE  exclude entries smaller than SIZE if positive,
                          or entries greater than SIZE if negative
      --time            show time of the last modification of any file in the
                          directory, or any of its subdirectories
      --time=WORD       show time as WORD instead of modification time:
                          atime, access, use, ctime or status
      --time-style=STYLE  show times using STYLE, which can be:
                            full-iso, long-iso, iso, or +FORMAT;
                            FORMAT is interpreted like in 'date'
  -X, --exclude-from=FILE  exclude files that match any pattern in FILE
      --exclude=PATTERN    exclude files that match PATTERN
  -x, --one-file-system    skip directories on different file systems
      --help        display this help and exit
      --version     output version information and exit

Display values are in units of the first available SIZE from --block-size,
and the DU_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables.
Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).

The SIZE argument is an integer and optional unit (example: 10K is 10*1024).
Units are K,M,G,T,P,E,Z,Y,R,Q (powers of 1024) or KB,MB,... (powers of 1000).
Binary prefixes can be used, too: KiB=K, MiB=M, and so on.

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Full documentation <https://www.gnu.org/software/coreutils/du>
or available locally via: info '(coreutils) du invocation'
$
$ sw_vers
ProductName:	macOS
ProductVersion:	12.6.5
BuildVersion:	21G531
$
$ type du
du is hashed (/opt/homebrew/opt/coreutils/libexec/gnubin/du)
$
@solidiquis
Copy link
Owner

You can get du's -s and -h behavior doing the following:

Screen Shot 2023-05-26 at 10 05 11 AM

I don't currently support allowing people to specify a custom block-size, defaulting instead to 512-byte units, I'm guessing that's what you're after?

@failable
Copy link

Screenshot 2023-06-19 at 22 31 47

@solidiquis I don't seem to get your command erd -L1 -iH. work. Why target/ is still ignored here?

@solidiquis
Copy link
Owner

@liebkne do you perhaps have a config file that's using the --pattern to filter? If so could you try passing --no-config? It works for me

Screen Shot 2023-06-19 at 7 56 43 AM

Let me know if the issue persists.

@failable
Copy link

@solidiquis Hi, I don't have any config file.

Screenshot 2023-06-20 at 12 45 13

Also, the Matching du output example in README does not seem to work for me.

Screenshot 2023-06-20 at 12 47 53

@solidiquis
Copy link
Owner

@liebkne last question before I dig further.. are any of the following environment variables set for you?

DU_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE

@failable
Copy link

Screenshot 2023-06-21 at 09 43 03 @solidiquis None of them is set.

@johnnyutahh
Copy link
Author

johnnyutahh commented Jul 2, 2023

The example quoted below is quite helpful, thanks @solidiquis.

After using erd a bit more, here's my list of things that would make it closer to "perfect" for me as a du replacement... I think. (I'm still learning erd.)

  1. du --summarize . (to enable summarizing size of a single directory, with only one line of output)
  2. du --block-size [...] (so: "yes, and then some" the answer to the question below)
  3. option to appropriately format erd's stdout for pipeline-stdin for other commands, like sort; eg, eliminate the footer line(s), maybe other things? eg: du -sh * | sort -rn is something I've run regularly in the past; said example may be no longer needed with erd's built-in sort capability, but being pipeline-extendable for reasons that we can not fully predict now is possibly a useful thing for general adoption, replace-ability of other commands (like du), scalability (of erd), etc.
  4. sort-able --color=force output. This may only be an issue for sort (or any other next-in-the-pipeline command) rather than erd. Comments or suggestions welcome.

You can get du's -s and -h behavior doing the following:

Screen Shot 2023-05-26 at 10 05 11 AM I don't currently support allowing people to specify a custom block-size, [defaulting instead to 512-byte units](https://doc.rust-lang.org/std/os/linux/fs/trait.MetadataExt.html#tymethod.st_blocks), I'm guessing that's what you're after?

@johnnyutahh johnnyutahh changed the title Features like du -shBm available, now or in future? Can 'erd' offer a 'du' replacement features for '--summarize', '--block-size' and pipeline-able stdout? Jul 2, 2023
@johnnyutahh
Copy link
Author

I'm highlighting @liebkne's question (above), in case it deserves its own issue or focus or some such.

Screenshot 2023-06-19 at 22 31 47 @solidiquis I don't seem to get your command `erd -L1 -iH.` work. Why `target/` is still ignored here?

@johnnyutahh johnnyutahh changed the title Can 'erd' offer a 'du' replacement features for '--summarize', '--block-size' and pipeline-able stdout? Can 'erd' offer a 'du'-replacement features for '--summarize', '--block-size' and pipeline-able stdout? Jul 2, 2023
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

3 participants