Repository navigation
feat: accept legacy -N line counts in head and tail - #171
Merged
ferdingler merged 2 commits intoOct 23, 2026
Merged
Conversation
head -3 file and tail -20 now mean -n 3 and -n 20, as in GNU coreutils. Only the first argument is read as a legacy count, so a dash-prefixed operand after -- stays a filename.
zastrowm
approved these changes
Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
headandtailonly understood-n 3, so the short legacy form likehead -3 fileortail -20failed with an unknown option. Agents write that form all the time, so a lot of ordinary commands just errored out.Now a leading
-Nmeans-n Nfor both commands, the same way GNU coreutils reads it. Like GNU, only the first argument counts, so anything after--stays a filename and a count in a later position is still rejected. The byte-count options work as before.Evidence of how we fixed it in Box
Box has its own fix for this (here); this version is written fresh for upstream, since Box's also treats a filename after
--as a count.Related Issues
None.
Documentation PR
None.
Type of Change
New feature
Testing
I compared the cases against GNU head and tail locally and they match, apart from one: GNU tail refuses a legacy count combined with
-n, and here the later option wins, the same as head. On main the new legacy-count tests failed. I also tried the simpler version that rewrites every-Nargument, and the tests for a dash-named file after--caught it. The full Rust suite passes and clippy shows no new warnings.cargo test --workspace --all-targets,pytest tests/python,npm test)cargo fmtandcargo clippyChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.