After searching the web , I came up with the below one line solution based mostly on the answer provided here : https://superuser.com/a/294164 and https://stackoverflow.com/a/23478116
The below solution first uses find command to find files (starting from current directory) and then pipes the output to perl command to do the sort and then pipes the resultant list of files into another perl command to get the timestamp of each of the file in a desired format.The result will show Top 5 oldest files.
I am not a perl expert but i am guessing the below can further be simplifed. Please do let me know if this is the case. The below solution seems to be working fine as of now.It works well on my AIX system.
find . -type f -print 2>/dev/null |
perl -l -ne '
$_{$_} = -M;
END {
$,="\n";
@sorted = sort {$_{$b} <=> $_{$a}} keys %_;
print @sorted[0..5];
}' | xargs -I {} perl -MPOSIX -e 'print "\n $ARGV[0] -------> $1 " . strftime("%A %Y-%m-%d %H:%M:%S", localtime((stat "$ARGV[0]")[9])) ' {}
This gives an output as follows:
./file1.txt ---> Sunday 2018-03-04 15:20:32
./sample/file2.sh ---> Sunday 2019-01-27 08:30:45
./test/file3.txt ---> Tuesday 2019-05-21 18:45:32
./sample/temp/file4.sh ---> Friday 2019-12-27 12:30:45
./file5.txt ---> Tuesday 2020-06-13 15:20:32