Find the oldest file in Unix or Linux file system

Posted on in Categories Link last updated October 28, 2016

So I wanted to know the oldest file on my Debian Linux box.

find / -type f -printf '%T+ %p\n' | sort | head -n 1
Here is an another example for /etc/
find /etc/ -type f -printf '%T+ %p\n' | sort | head -n 10

Find the top 10 oldest file in a directory tree on GNU/Linux
Find the top 10 oldest file in a directory tree on GNU/Linux

So find command finds all files in / and print it with a special format. The %T+ (in -printf) means file’s last modification date and time in separated by +, for example ‘2004-04-28+22:22:05.0’. This is a GNU extension and may not work on other BSD/find or any other version of find. The %p indicts the file name. The sort command sorted input and passed it to head to display the oldest file on my GNU/Linux system. The sort command sorted input and passed it to head to display the oldest file on my GNU/Linux system. Cool, eh?

(Credit: Ubuntu forums).

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Leave a Comment