DATESORT(1)
π datesort(1) β the manual, but make it a group chat π
okay bestie, so datesort is a User Command and this whole page is basically me explaining it to you while we're both supposed to be doing something else. no cap, it's a good one. stay with me π«Ά
β¨ NAME β¨
datesort β sort the contents of FILE chronologically. that's it. that's the whole job. iconic behavior honestly π
β¨ SYNOPSIS β¨
datesort [OPTION]... [FILE]...
β¨ DESCRIPTION β¨
Sort the contents of FILE chronologically. If you don't give it a FILE, it literally just reads from stdin, no big deal π
The first date/time value on each line is the sort key. one per line, first one wins, periodt.
now here's the ranking drama you need to know, because the ordering rules are lowkey specific:
- Dates that have no time count as a smaller value than any date/time on the same day.
- Times that have no date count as a smaller value than any date or date/time.
- If a line has no dates, times, or date/times at all, it gets sorted towards the front. yes bestie, the dateless lines are first in line π
Here are the recognized OPTIONs:
-h,--helpβ print help and exit β¨-V,--versionβ print version and exit-i,--input-format=STRING...β the input format. you can pass this multiple times and it's giving very thorough. Each date/time gets handed to the input format parsers in the order you gave them, and if a date/time can be read successfully with a given input format specifier string, that value is the one that gets used π―-b,--base=DTβ for underspecified input, useDTas a fallback to fill in the missing fields. it's also used for ambiguous format specifiers, to position their range on the absolute time line. it must be a date/time in ISO8601 format. if you omit it, it defaults to the current date/time β°-e,--backslash-escapesβ turn on interpretation of backslash escapes in the input format specifier strings πͺ--from-locale=LOCALEβ interpret dates on stdin or on the command line as coming from the localeLOCALE. ngl this would only affect month and weekday names, because input formats have to be specified explicitly anyway π--from-zone=ZONEβ interpret dates on stdin or the command line as coming from the time zoneZONEπ°οΈ-r,--reverseβ flip the sort order. chaos mode, but make it chronological-backwards π-u,--uniqueβ print at most one line per date/time value. no duplicates, we're keeping it exclusive π
β¨ FORMAT SPECS β¨
Format specs in dateutils are similar to posix' strftime().
BUT β and this is the plot twist β because dateutils supports a broader range of calendars, it has to employ different rules. so don't come at it expecting strftime to carry you, bestie π
π Date specs:
%aβ the abbreviated weekday name%Aβ the full weekday name%_aβ the weekday name shortened to a single character (MTWRFAS)%bβ the abbreviated month name%Bβ the full month name%_bβ the month name shortened to a single character (FGHJKMNQUVXZ)%cβ the count of the weekday within the month (range00to05)%Cβ the count of the weekday within the year (range00to53)%dβ the day of the month, 2 digits (range00to31)%Dβ the day of the year, 3 digits (range000to366)%Fβ equivalent to%Y-%m-%d(ymd's canonical format)%gβ ISO week date year without the century (range00to99)%Gβ ISO week date year including the century%jβ equivalent to%D%mβ the month in the current calendar (range00to12)%Qβ the quarter of the year (rangeQ1toQ4)%qβ the number of the quarter (range01to04)%sβ the number of seconds since the Epoch.%uβ the weekday as number (range01to07, Sunday being07)%Uβ the week count, day of week is Sun (range00to53)%Vβ the ISO week count, day of week is Mon (range01to53)%wβ the weekday as number (range00to06, Sunday being00)%Wβ the week count, day of week is Mon (range00to53)%yβ the year without a century (range00to99)%Yβ the year including the century%_yβ the year shortened to a single digit%Zβ the zone offset in hours and minutes (HH:MM) with a preceding sign (+for offsets east of UTC,-for offsets west of UTC)%Odβ the day as roman numerals%Omβ the month as roman numerals%Oyβ the two digit year as roman numerals%OYβ the year including the century as roman numerals%rsβ in time systems whose Epoch is different from the unix Epoch, this selects the number of seconds since then.%rYβ in calendars with years that don't coincide with the Gregorian years, this selects the calendar's year.%dthβ the day of the month as an ordinal number,1st,2nd,3rd, etc.%mthβ the month of the year as an ordinal number,1st,2nd,3rd, etc.%dbβ the business day of the month (since last month's ultimo)%dBβ number of business days until this month's ultimo
π Time specs:
%Hβ the hour of the day using a 24h clock, 2 digits (range00to23)%Iβ the hour of the day using a 12h clock, 2 digits (range01to12)%Mβ the minute (range00to59)%Nβ the nanoseconds (range000000000to999999999)%pβ the stringAMorPM, noon isPMand midnight isAM.%Pβ like%pbut in lowercase%Sβ the seconds (range00to60,60is for leap seconds)%Tβ equivalent to%H:%M:%S
π General specs:
%nβ a newline character%tβ a tab character%%β a literal%character
π Modifiers:
%Oβ modifier to turn decimal numbers into Roman numerals%rβ modifier to turn units into real units%0β modifier to turn on zero prefixes%SPCβ modifier to turn on space prefixes%-β modifier to turn off prefixes altogetherthβ suffix, read and print ordinal numbersbβ suffix, treat days as business days
β οΈ and this one is important fr fr: by design, dates before 1601-01-01 are not supported. do not come for it, it simply will not do it π
For conformity, here is a list of calendar designators and their corresponding format string:
ymdβ%Y-%m-%dymcwβ%Y-%m-%c-%wywdβ%rY-W%V-%ubizdaβ%Y-%m-%dblilianβ n/aldnβ n/ajulianβ n/ajdnβ n/amatlabβ n/amdnβ n/a
These designators can be used as output format string, and moreover, @code{lilian}/@code{ldn} and @code{julian}/@code{jdn} can also be used as input format string. slay β¨
β¨ EXAMPLES β¨
reading from stdin, iconic:
$ datesort < "$@{srcdir@}/caev_01.txt"
2009-06-03 caev="DVCA" secu="VOD" exch="XLON" xdte="2009-06-03" nett/GBX="5.2"
2010-11-17 caev="DVCA" secu="VOD" exch="XLON" xdte="2010-11-17" nett/GBX="2.85"
2011-11-16 caev="DVCA" secu="VOD" exch="XLON" xdte="2011-11-16" nett/GBX="3.05"
2012-06-06 caev="DVCA" secu="VOD" exch="XLON" xdte="2012-06-06" nett/GBX="6.47"
2013-06-12 caev="DVCA" secu="VOD" exch="XLON" xdte="2013-06-12" nett/GBX="6.92"
2013-11-20 caev="DVCA" secu="VOD" exch="XLON" xdte="2013-11-20" nett/GBX="3.53"
$
and now passing the file as an argument, same energy, same output π«Ά:
$ datesort "$@{srcdir@}/caev_01.txt"
2009-06-03 caev="DVCA" secu="VOD" exch="XLON" xdte="2009-06-03" nett/GBX="5.2"
2010-11-17 caev="DVCA" secu="VOD" exch="XLON" xdte="2010-11-17" nett/GBX="2.85"
2011-11-16 caev="DVCA" secu="VOD" exch="XLON" xdte="2011-11-16" nett/GBX="3.05"
2012-06-06 caev="DVCA" secu="VOD" exch="XLON" xdte="2012-06-06" nett/GBX="6.47"
2013-06-12 caev="DVCA" secu="VOD" exch="XLON" xdte="2013-06-12" nett/GBX="6.92"
2013-11-20 caev="DVCA" secu="VOD" exch="XLON" xdte="2013-11-20" nett/GBX="3.53"
$
now -r, the reverse girlies:
$ datesort -r < "$@{srcdir@}/caev_01.txt"
2013-11-20 caev="DVCA" secu="VOD" exch="XLON" xdte="2013-11-20" nett/GBX="3.53"
2013-06-12 caev="DVCA" secu="VOD" exch="XLON" xdte="2013-06-12" nett/GBX="6.92"
2012-06-06 caev="DVCA" secu="VOD" exch="XLON" xdte="2012-06-06" nett/GBX="6.47"
2011-11-16 caev="DVCA" secu="VOD" exch="XLON" xdte="2011-11-16" nett/GBX="3.05"
2010-11-17 caev="DVCA" secu="VOD" exch="XLON" xdte="2010-11-17" nett/GBX="2.85"
2009-06-03 caev="DVCA" secu="VOD" exch="XLON" xdte="2009-06-03" nett/GBX="5.2"
$
same thing but with the file argument:
$ datesort -r "$@{srcdir@}/caev_01.txt"
2013-11-20 caev="DVCA" secu="VOD" exch="XLON" xdte="2013-11-20" nett/GBX="3.53"
2013-06-12 caev="DVCA" secu="VOD" exch="XLON" xdte="2013-06-12" nett/GBX="6.92"
2012-06-06 caev="DVCA" secu="VOD" exch="XLON" xdte="2012-06-06" nett/GBX="6.47"
2011-11-16 caev="DVCA" secu="VOD" exch="XLON" xdte="2011-11-16" nett/GBX="3.05"
2010-11-17 caev="DVCA" secu="VOD" exch="XLON" xdte="2010-11-17" nett/GBX="2.85"
2009-06-03 caev="DVCA" secu="VOD" exch="XLON" xdte="2009-06-03" nett/GBX="5.2"
$
and -u, where we keep it exclusive and only print one line per date/time value π
:
$ datesort -u < "$@{srcdir@}/caev_02.txt"
2009-06-03 caev="DVCA" secu="VOD" exch="XLON" xdte="2009-06-03" nett/GBX="5.2"
2010-11-17 caev="XXXX" secu="VOD" exch="XLON" xdte="2010-11-17"
2011-11-16 caev="DVCA" secu="VOD" exch="XLON" xdte="2011-11-16" nett/GBX="3.05"
2012-06-06 caev="DVCA" secu="VOD" exch="XLON" xdte="2012-06-06" nett/GBX="6.47"
2013-06-12 caev="DVCA" secu="VOD" exch="XLON" xdte="2013-06-12" nett/GBX="6.92"
2013-11-20 caev="DVCA" secu="VOD" exch="XLON" xdte="2013-11-20" nett/GBX="3.53"
$
aaaand once more with the file argument, because consistency is the whole vibe:
$ datesort -u "$@{srcdir@}/caev_02.txt"
2009-06-03 caev="DVCA" secu="VOD" exch="XLON" xdte="2009-06-03" nett/GBX="5.2"
2010-11-17 caev="XXXX" secu="VOD" exch="XLON" xdte="2010-11-17"
2011-11-16 caev="DVCA" secu="VOD" exch="XLON" xdte="2011-11-16" nett/GBX="3.05"
2012-06-06 caev="DVCA" secu="VOD" exch="XLON" xdte="2012-06-06" nett/GBX="6.47"
2013-06-12 caev="DVCA" secu="VOD" exch="XLON" xdte="2013-06-12" nett/GBX="6.92"
2013-11-20 caev="DVCA" secu="VOD" exch="XLON" xdte="2013-11-20" nett/GBX="3.53"
$
β¨ AUTHOR β¨
Written by Sebastian Freundt <freundt@fresse.org> π
β¨ REPORTING BUGS β¨
Report bugs to: https://github.com/hroptatyr/dateutils/issues
(be nice, bestie, they're doing their best π«Ά)
β¨ SEE ALSO β¨
The full documentation for datesort is maintained as a Texinfo manual. If the info and datesort programs are properly installed at your site, the command
info (dateutils)datesort
should give you access to the complete manual. iykyk π¦
okay that's the whole page, thank you for coming to my ted talk πΈ
this was dateutils 0.4.11, dated November 2025 β DATESORT(1) and out, love u, bye πβ¨π
π¦ where this page comes from
- ubuntu resolute: dateutils 0.4.11-2 Β· BSD-3-Clause
- ubuntu stonking: dateutils 0.4.11-2 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms