mc icon indicating copy to clipboard operation
mc copied to clipboard

feat: allow to list objects sorted by size

Open iTrooz opened this issue 1 month ago • 6 comments

Community Contribution License

All community contributions in this pull request are licensed to the project maintainers under the terms of the Apache 2 license. By creating this pull request I represent that I have the right to license the contributions to the project maintainers under the Apache 2 license.

Description & context

Add a --sort=size option to mcli ls to be able to sort files by size

Usually, you would do that by piping to sort, or using the --sort flag of ls

How to test this PR?

Compare go run . ls <path> and go run . ls <path> --sort=size

Types of changes

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)
  • [ ] Optimization (provides speedup with no functional changes)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • [ ] Fixes a regression (If yes, please add commit-id or PR # here)
  • [ ] Unit tests added/updated
  • [ ] Internal documentation updated (??)
  • [ ] Create a documentation update request here

iTrooz avatar Nov 12 '25 14:11 iTrooz

I'm waiting for initial feature approval before adding tests/making a PR to the docs repo

iTrooz avatar Nov 12 '25 14:11 iTrooz

@shtripat @harshavardhana Hello ! Would it be possible to review this PR please ? Thank you

iTrooz avatar Dec 04 '25 08:12 iTrooz

I am confused about the value add of this feature. If we really need such a thing, we can use --json output and then sort as and when needed. Something like mc ls ALIAS/BUCKET -r --json | jq -s 'sort_by(.size) | .[] | {key, size}'

shtripat avatar Dec 04 '25 08:12 shtripat

We could do that, but but the --json | jq -s 'sort_by(.size) | .[] | {key, size}' part is a bit cumbersome (I personally wouldn't be able to pull it off in a reasonable time), which is why I added the --sort. It is purely a QoL feature

iTrooz avatar Dec 04 '25 08:12 iTrooz

We could do that, but but the --json | jq -s 'sort_by(.size) | .[] | {key, size}' part is a bit cumbersome (I personally wouldn't be able to pull it off in a reasonable time), which is why I added the --sort. It is purely a QoL feature

IIUC this kind of sorting is needed when we are programmatically processing the output and --json is meant to be used for this purpose. But lets hear from Harsha as well.

shtripat avatar Dec 04 '25 08:12 shtripat

My use case was "I want to see what the biggest files are in this bucket" (not in the context of a script, purely me out of curiosity) Maybe there is already a way to do that that I missed ?

But lets hear from Harsha as well.

Ok !

iTrooz avatar Dec 04 '25 08:12 iTrooz