SORT(1)

๐Ÿ’– SORT(1) ๐Ÿ’–

okay bestie, welcome to the sort manual page โ€” it lives in the User Commands section and it is genuinely one of the most iconic little gremlins in your whole toolkit. let's get into it ๐Ÿซถ


โœจ NAME โœจ

sort โ€” sort lines of text files


๐ŸŒธ SYNOPSIS ๐ŸŒธ

sort [OPTION]... [FILE]...
sort [OPTION]... --files0-from=F

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

So what it does: it writes the sorted concatenation of all the FILE(s) to standard output. that's it. that's the whole vibe. โœจ

If you give it no FILE, or if FILE is -, it reads from standard input. very demure, very mindful. ๐ŸŽ€

Also, mandatory arguments to long options are mandatory for short options too. like, don't try it. it's not optional. periodt.

๐Ÿ‘‘ Ordering options

  • -b, --ignore-leading-blanks โ€” ignore leading blanks when finding sort keys in each line. yes queen, skip the whitespace ๐Ÿ’…
  • -d, --dictionary-order โ€” only consider blanks and alphanumeric characters. everything else? not invited to the function ๐Ÿšซ
  • -f, --ignore-case โ€” fold lower case to upper case characters. case? we don't know her ๐Ÿ”ฅ
  • -g, --general-numeric-sort โ€” compare according to general numerical value. the math-y one ๐Ÿงฎ
  • -i, --ignore-nonprinting โ€” consider only printable characters. invisible stuff, be gone ๐Ÿซฅ
  • -M, --month-sort โ€” compare (unknown) < 'JAN' < ... < 'DEC'. literally a calendar girl moment ๐Ÿ“…
  • -h, --human-numeric-sort โ€” compare human readable numbers (e.g., 2K 1G). for the girlies who say "2K" instead of "2048" ๐Ÿ’–
  • -n, --numeric-sort โ€” compare according to string numerical value; see full documentation for supported strings. ngl the docs are where the details live ๐Ÿ‘€
  • -R, --random-sort โ€” shuffle, but group identical keys. See also shuf(1). chaos, but organized chaos ๐ŸŽฒ
  • --random-source=FILE โ€” get random bytes from FILE. your randomness has a source now โœจ
  • -r, --reverse โ€” reverse the result of comparisons. plot twist ๐Ÿ”„
  • --sort=WORD โ€” sort according to WORD: general-numeric -g, human-numeric -h, month -M, numeric -n, random -R, version -V. one option, six personalities ๐ŸŒˆ
  • -V, --version-sort โ€” natural sort of (version) numbers within text. so v2 comes before v10, as it should ๐Ÿ™Œ

๐ŸŽ€ Other options

  • --batch-size=NMERGE โ€” merge at most NMERGE inputs at once; for more use temp files. don't overbook the merge bestie ๐Ÿ˜Œ
  • -c, --check, --check=diagnose-first โ€” check for sorted input; do not sort. just vibes and judgement ๐Ÿ”
  • -C, --check=quiet, --check=silent โ€” like -c, but do not report first bad line. silent but deadly ๐Ÿคซ
  • --compress-program=PROG โ€” compress temporaries with PROG; decompress them with PROG -d. glow-up via compression ๐Ÿ’…
  • --debug โ€” annotate the part of the line used to sort, and warn about questionable usage to standard error. the friend who tells you the truth ๐Ÿซถ
  • --files0-from=F โ€” read input from the files specified by NUL-terminated names in file F; If F is -, read names from standard input. NUL-terminated, not newline-terminated, important bestie โš ๏ธ
  • -k, --key=KEYDEF โ€” sort via a key; KEYDEF gives location and type. the main character option fr fr ๐Ÿ‘‘
  • -m, --merge โ€” merge already sorted files; do not sort. it trusts you. don't betray it ๐Ÿ˜ญ
  • -o, --output=FILE โ€” write result to FILE instead of standard output. redirect, but make it chic ๐ŸŽ
  • -s, --stable โ€” stabilize sort by disabling last-resort comparison. stable like your fave ๐ŸŒธ
  • -S, --buffer-size=SIZE โ€” use SIZE for main memory buffer. feed the machine ๐Ÿ“
  • -t, --field-separator=SEP โ€” use SEP instead of non-blank to blank transition. custom separator, custom era โœ‚๏ธ
  • -T, --temporary-directory=DIR โ€” use DIR for temporaries, not $TMPDIR or /tmp; multiple options specify multiple directories. hoard directories, why not ๐Ÿ 
  • --parallel=N โ€” change the number of sorts run concurrently to N. multitasking queen ๐Ÿ’ซ
  • -u, --unique โ€” output only the first of lines with equal keys; with -c, check for strict ordering. duplicates? never met her ๐Ÿšซ
  • -z, --zero-terminated โ€” line delimiter is NUL, not newline. NUL gang rise up ๐Ÿซก
  • --help โ€” display this help and exit. the classic ๐ŸŽ€
  • --version โ€” output version information and exit. the other classic ๐ŸŽ€

๐Ÿ’œ KEYDEF, explained (the part everyone skips and then regrets)

KEYDEF is F[.C][OPTS][,F[.C][OPTS]] for start and stop position, where F is a field number and C a character position in the field; both are origin 1, and the stop position defaults to the line's end.

If neither -t nor -b is in effect, characters in a field are counted from the beginning of the preceding whitespace. lowkey feral but okay ๐Ÿ‘€

OPTS is one or more single-letter ordering options [bdfgiMhnRrV], which override global ordering options for that key.

If no key is given, use the entire line as the key.

Use --debug to diagnose incorrect key usage. seriously. do it. it will save your whole evening ๐Ÿ˜ญ

๐Ÿงš SIZE suffixes

SIZE may be followed by the following multiplicative suffixes: % 1% of memory, b 1, K 1024 (default), and so on for M, G, T, P, E, Z, Y, R, Q.


โš ๏ธ *** WARNING *** The locale specified by the environment affects sort order. Set LC_ALL=C to get the traditional sort order that uses native byte values. not me finding out my sort order was locale-coded the whole time ๐Ÿ’€

๐ŸŒŸ AUTHOR ๐ŸŒŸ

Written by Mike Haertel and Paul Eggert. legends, honestly ๐Ÿ‘‘


๐Ÿ“ข REPORTING BUGS ๐Ÿ“ข


Copyright ยฉ 2026 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.


๐Ÿฆ„ SEE ALSO ๐Ÿฆ„

Full documentation <https://www.gnu.org/software/coreutils/sort> or available locally via: info '(coreutils) sort invocation'


and that's the whole page bestie ๐Ÿ’– this was GNU coreutils 9.12, dated September 2026 โ€” go forth and sort your lines, you absolute icon, no cap ๐ŸŽ€โœจ๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from