11

How to do sort -V in alpine linux?

sort: unrecognized option: V
BusyBox v1.28.4 (2018-12-06 15:13:21 UTC) multi-call binary.

Usage: sort [-nrugMcszbdfiokt] [-o FILE] [-k start[.offset][opts][,end[.offset][opts]] [-t CHAR] [FILE]...

Sort lines of text

    -o FILE Output to FILE
    -c  Check whether input is sorted
    -b  Ignore leading blanks
    -f  Ignore case
    -i  Ignore unprintable characters
    -d  Dictionary order (blank or alphanumeric only)
    -g  General numerical sort
    -M  Sort month
    -n  Sort numbers
    -t CHAR Field separator
    -k N[,M] Sort by Nth field
    -r  Reverse sort order
    -s  Stable (don't sort ties alphabetically)
    -u  Suppress duplicate lines
    -z  Lines are terminated by NUL, not newline
Kusalananda
  • 333,661
Rex Lam
  • 213

3 Answers3

16

With Alpine, you can add GNU sort via the coreutils package:

apk add coreutils
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
3

The implementation of sort in release 1.30.0 of BusyBox (December 2018) introduced -V for doing "version sorting", just like in GNU sort.

BusyBox 1.30.1 was included in Alpine Linux in release 3.10 (June 2019), so you do not need the coreutils package anymore.

Kusalananda
  • 333,661
U. Bulle
  • 131
  • 1
  • While the short form -V seems to be supported, the long-form --version-sort seems not supported. So make sure you use the short form if you want a portable solution. – lanoxx Jan 26 '24 at 15:42
  • Busybox sort has functional differences as compared to GNU sort. So, it may not be a drop-in replacement. E.g. If a folder has files named 01 A, 02 B & 011 C, GNU sort gives A, B, C, while Busybox gives A C B. So, you may still need coreutils. – Mohnish Feb 11 '24 at 03:03
1

In alpine, sort - V (version) is not supported.

Bear in mind that it's the busybox version and not the coreutis sort version.

Such is the price to pay to have a very light distribution.

Note that you can always add compiled binaries and glibc itself to alpine, or even static linked j binaries, but once you start doing that, you are adding more substantial size to it.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
  • There is also posts about how to working around not having sort here, I am in my the tube now, cannot get links – Rui F Ribeiro Jan 29 '19 at 10:09
  • I installed coreutils instead of out of the box one, and it works – Rex Lam Jan 30 '19 at 01:12
  • Yeah, it works adding it, though I am no alpine user. The point is that coreutils is big. If you keep adding size to alpine, it comes to a point where it could make more sense using a cut down image of Debian., you can make 200-300 MB images of Debian, already with APT and security updates if you know what you are doing. – Rui F Ribeiro Jan 30 '19 at 01:59
  • I know and agree what you say, the filesize of coreutils is not small for alpine but it is still acceptable for my use case as I'm not deploying it to an embedded device, thus, it would be a good balance for me :) – Rex Lam Jan 30 '19 at 02:36
  • 1
    See related: https://unix.stackexchange.com/questions/419697/why-are-true-and-false-so-large/419704#419704 ; however my concerns about Alpine is that once you lose that size advantage, it does not make sense keeping using it. (less supported, binaries built with musl instead of glibc, probably less updates during lesser time) – Rui F Ribeiro Jan 30 '19 at 02:53