Find oldest file on UNIX/BSD
source link: https://hauweele.net/~gawen/blog/?p=2641
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Post navigation
Find oldest file on UNIX/BSD
If you wish to find the oldest file in a directory tree on a UNIX system, you might have found the following solution:
find . -type f -printf '%T+ %p\n' | sort | head -n 1
This is all good and nice, but it only works with the GNU version of findutils. Indeed other versions of find
do not support the -printf
option. A more compatible option goes something like that (it’s at the same time more generic (doesn’t use -printf
) and more BSD specific (stat syntax) but you might adapt it to Linux easily):
find . -type f | xargs stat -f "%m %N" | sort | head -n 1
This entry was posted in Uncategorized and tagged bsd, find, freebsd, oldest, unix by gawen. Bookmark the permalink.
Leave a Reply Cancel reply
Your email address will not be published. Required fields are marked *
Comment *
Name *
Email *
Website
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK