I wanted to find some really old programs, so I turned my attention to oldest ebuilds. There was a piece of Python code can do this task, but I wanted one can be done with more common commands.

Initially, I have this:


$ find /usr/portage -name '*.ebuild' -mtime +$((365 * 9)) -ls
3246743 4 -rw-r--r-- 1 portage portage 770 Oct 27 2004 /usr/portage/sys-cluster/xgridagent/xgridagent-1.0.ebuild
3138612 4 -rw-r--r-- 1 portage portage 705 Jul 19 2004 /usr/portage/media-gfx/springgraph/springgraph-79.ebuild
3246544 4 -rw-r--r-- 1 portage portage 567 Oct 16 2004 /usr/portage/sys-boot/raincoat/raincoat-0.5.ebuild
3277980 4 -rw-r--r-- 1 portage portage 683 Jun 25 2004 /usr/portage/x11-libs/libiterm-mbt/libiterm-mbt-0.5.ebuild

It does the job, but it needs the amount of days for -mtime, not really what I was looking for, if you want # most oldest. So, here is another way to do it:


$ find /usr/portage -name '*.ebuild' -printf '%T+ %p\n' | sort | head
2004-06-25+06:05:04.0000000000 /usr/portage/x11-libs/libiterm-mbt/libiterm-mbt-0.5.ebuild
2004-07-19+09:54:10.0000000000 /usr/portage/media-gfx/springgraph/springgraph-79.ebuild
2004-10-16+23:07:47.0000000000 /usr/portage/sys-boot/raincoat/raincoat-0.5.ebuild
2004-10-27+20:13:20.0000000000 /usr/portage/sys-cluster/xgridagent/xgridagent-1.0.ebuild
2004-11-26+05:46:53.0000000000 /usr/portage/net-irc/ptlink-opm/ptlink-opm-1.3.1.ebuild
2004-12-29+05:19:57.0000000000 /usr/portage/dev-tex/rcsinfo/rcsinfo-1.9.ebuild
2005-01-01+20:50:10.0000000000 /usr/portage/app-dicts/dictd-vera/dictd-vera-1.7-r1.ebuild
2005-01-01+20:50:10.0000000000 /usr/portage/app-dicts/dictd-vera/dictd-vera-1.9_pre.ebuild
2005-01-01+22:19:05.0000000000 /usr/portage/app-emulation/vmips-cross-bin/vmips-cross-bin-1.0.ebuild
2005-01-01+22:54:50.0000000000 /usr/portage/app-misc/cbview/cbview-0.06.ebuild

Note

You can replace %p with %P to get a relative path to /usr/portage, instead of an absolute path.

Using -printf to print out the timestamp with sort and head to get the oldest # files. If you want to discard or do more, then piping into cut -d ' ' -f 2- can get rid of timestamp. But some characters might get into your way, I don’t really have good and simple solution for every unusual character, but the following command can tackle spaces without an issue:


find . -printf '%T+ %p\n' | sort | head | cut -d ' ' -f 2- | tr '\n' '\000' | xargs -0 the_command

If head and cut could process zero-terminal NUL input, then this would be doable. Unfortunately, only sort can do so. However, if using with -mtime, then it’s much simpler to deal with strange characters:


find . -type f -mtime +365 -print0 | xargs -0 the_command

Only cons are no sorting and oldest #.

If might be better to write your only script to handle those characters, but I always wonder why would someone put \n or even a tab character in filename?