`tail` command misbehaving

I am trying to understand the weird behaviour of tail on nixOS.
Version is tail (GNU coreutils) 9.8.

When I try to limit the output of less with -n, I can go up to 31 lines. Once I do -n 32, no line is printed. As if the formula for the actual line limit was $(-n) % 32. After that, the wrap is every 71 lines. Doing -n 103 yields 0 lines, as does 174, 245, and so on.

Can anyone reproduce this behaviour?
What could be the reason for this?

Looks correct to me…

$ for n in $(seq 1 100); do tail -n $n ~/.local/state/nvim/lsp.log|wc -l; done
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
$ tail --version
tail (GNU coreutils) 9.8
Packaged by https://nixos.org
Copyright (C) 2025 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Paul Rubin, David MacKenzie, Ian Lance Taylor,
and Jim Meyering.

For me the output of your command looks like

...
72
73
74
75
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

This output is different from what you describe above, but still off…

Did you somehow change your coreutils via patches? Or do you have any overlays? Can you perhaps share your config in its entirety?

And what Channel are you using?

The overflow parameters vary from file to file.
This works on my machine:

for i in $(seq 5000000); do echo i: $i; done > list.txt
tail -n 175 list.txt

yields an empty line.

I get

collapsed output
i: 4999826
i: 4999827
i: 4999828
i: 4999829
i: 4999830
i: 4999831
i: 4999832
i: 4999833
i: 4999834
i: 4999835
i: 4999836
i: 4999837
i: 4999838
i: 4999839
i: 4999840
i: 4999841
i: 4999842
i: 4999843
i: 4999844
i: 4999845
i: 4999846
i: 4999847
i: 4999848
i: 4999849
i: 4999850
i: 4999851
i: 4999852
i: 4999853
i: 4999854
i: 4999855
i: 4999856
i: 4999857
i: 4999858
i: 4999859
i: 4999860
i: 4999861
i: 4999862
i: 4999863
i: 4999864
i: 4999865
i: 4999866
i: 4999867
i: 4999868
i: 4999869
i: 4999870
i: 4999871
i: 4999872
i: 4999873
i: 4999874
i: 4999875
i: 4999876
i: 4999877
i: 4999878
i: 4999879
i: 4999880
i: 4999881
i: 4999882
i: 4999883
i: 4999884
i: 4999885
i: 4999886
i: 4999887
i: 4999888
i: 4999889
i: 4999890
i: 4999891
i: 4999892
i: 4999893
i: 4999894
i: 4999895
i: 4999896
i: 4999897
i: 4999898
i: 4999899
i: 4999900
i: 4999901
i: 4999902
i: 4999903
i: 4999904
i: 4999905
i: 4999906
i: 4999907
i: 4999908
i: 4999909
i: 4999910
i: 4999911
i: 4999912
i: 4999913
i: 4999914
i: 4999915
i: 4999916
i: 4999917
i: 4999918
i: 4999919
i: 4999920
i: 4999921
i: 4999922
i: 4999923
i: 4999924
i: 4999925
i: 4999926
i: 4999927
i: 4999928
i: 4999929
i: 4999930
i: 4999931
i: 4999932
i: 4999933
i: 4999934
i: 4999935
i: 4999936
i: 4999937
i: 4999938
i: 4999939
i: 4999940
i: 4999941
i: 4999942
i: 4999943
i: 4999944
i: 4999945
i: 4999946
i: 4999947
i: 4999948
i: 4999949
i: 4999950
i: 4999951
i: 4999952
i: 4999953
i: 4999954
i: 4999955
i: 4999956
i: 4999957
i: 4999958
i: 4999959
i: 4999960
i: 4999961
i: 4999962
i: 4999963
i: 4999964
i: 4999965
i: 4999966
i: 4999967
i: 4999968
i: 4999969
i: 4999970
i: 4999971
i: 4999972
i: 4999973
i: 4999974
i: 4999975
i: 4999976
i: 4999977
i: 4999978
i: 4999979
i: 4999980
i: 4999981
i: 4999982
i: 4999983
i: 4999984
i: 4999985
i: 4999986
i: 4999987
i: 4999988
i: 4999989
i: 4999990
i: 4999991
i: 4999992
i: 4999993
i: 4999994
i: 4999995
i: 4999996
i: 4999997
i: 4999998
i: 4999999
i: 5000000

What shell are you using? I’m using zsh.

I am also using zsh on an imx8p

What does type -a tail report?

I’m pretty sure that’s the bug mentioned here coreutils-9.9 released [stable]

‘tail’ outputs the correct number of lines again for non-small -n values.
Previously it may have output too few lines.
[bug introduced in coreutils-9.8]

Arch had a patch for it: upgpkg: 9.8-2: fix upstream tail bug, reported by coreutils maintainer (ef4b5423) · Commits · Arch Linux / Packaging / Packages / coreutils · GitLab

4 Likes

Good find! We could try to get coreutils: 9.8 -> 9.9 by r-ryantm · Pull Request #460517 · NixOS/nixpkgs · GitHub moving to resolve this.