GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ls, lsl, lsd, lsf, lsjson: add --output-file flag - fixes #8358 by hsdfat · Pull Request #10279 · rclone/rclone

Conversation

@hsdfat

@hsdfat hsdfat commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

What does this change do?

Adds --output-file to ls, lsl, lsd, lsf and lsjson, so the listing can go to a file while --progress and the log keep the terminal. This is option 1 from the issue, which @ncw preferred over sending progress to stderr.

Today, redirecting stdout with -P captures the progress block as well, because the ls commands write through os.Stdout, which --progress intercepts (operations.SyncFprintf special-cases w == os.Stdout). A file passed to the same functions is written directly, so nothing new is needed in fs/operations.

  • cmd/ls/lshelp gets the flag and an Output() helper that returns os.Stdout or the created file, modelled on hashsum --output-file. It lives in lshelp because all five commands already import it for the shared help, which also gains a sentence about the flag. The name follows hashsum (and the issue) rather than tree --output.
  • ls, lsl, lsd and lsf pass the writer to the operations.List*/Lsf functions they already call with os.Stdout.
  • lsjson was the only one writing os.Stdout directly, with fmt.Print* for the brackets and separators. Its body moves into lsJSON(ctx, fsrc, remote, w io.Writer) and every write goes to w with the error checked. Output is unchanged: I compared lsjson -R and lsjson --stat from this branch and from master byte for byte on cmd/lsf/testfiles.

Without the flag all five commands still pass the real os.Stdout, so --progress interception behaves as before.

Testing

  • cmd/ls/lshelp/lshelp_test.go: Output() returns os.Stdout when the flag is empty, writes to and closes the file when set, and returns an error for a path that cannot be created.
  • cmd/lsjson/lsjson_test.go: lsJSON writes a parseable listing, and a --stat item, to the given writer, using cmd/lsf/testfiles; an empty directory gives exactly [\n]\n.
  • With the built binary on cmd/lsf/testfiles: ls, lsl, lsd, lsf, lsjson -R and lsjson --stat with --output-file leave stdout empty and write the listing to the file; lsjson -R --output-file x.json -P shows only the progress block on the terminal and x.json parses; a path in a missing directory fails with failed to create output file ....
  • go build ./..., go test -race on the five packages, and golangci-lint run (v2.15.0) on them all pass.

No change to docs/content/commands, which is generated at release time; the flag shows up in --help and the sentence in the shared help covers the usage.

Linked issue

Fixes #8358

Checklist

  • This change is trivial OR it has been discussed and agreed in the linked issue.
  • I have read the contribution guidelines.
  • (If I used AI tools to help write this code) I have read and understood the AI-assisted contributions guidance, and I have tested and take ownership of this change myself.
  • I have added tests for all changes in this PR if appropriate.
  • I have added documentation for the changes if appropriate.
  • All commit messages are in house style.
  • (Backend changes only) test_all passes for this backend and if submitting a new backend can provide a test account for the integration tester - see CONTRIBUTING.md.
  • This Pull Request is ready for review.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@hsdfat
ls, lsl, lsd, lsf, lsjson: add --output-file flag - fixes rclone#8358
e94e44b
Write the listing to a file instead of standard output. Progress and
log output keep going to the terminal, so a listing can be captured
while watching --progress.

lsjson wrote to os.Stdout directly; it now writes to the chosen writer.
@hsdfat
hsdfat requested a review from ncw as a code owner November 7, 2026 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ncw ncw Awaiting requested review from ncw ncw is a code owner

At least 1 approving review is required to merge this pull request.

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Ability to see progress when redirecting STDOUT

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@hsdfat
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.