Get the newest files based on date

Hello friends,
I'm learning to script, and I need help.

How can I get the latest/newest files based on date? the format is as following:

Feb 07 19:25 TESTPWD_file_1vk6pn40_19519_1
Feb 07 19:46 TESTPWD_file_1uk6pn40_19518_2
Feb 07 19:47 TESTPWD_file_20k6pn40_19520_2
Feb 07 19:56 TESTPWD_file_23k6po9j_19523_1
Feb 07 19:56 Config_TESTPWD_020709:19:10.TXT

Jun 06 19:38 TESTPWD_10204_file_77kgu17l_19687_1
Jun 06 19:40 TESTPWD_10204_file_7akgu17p_19690_1
Jun 06 20:05 TESTPWD_10204_file_7dkgu3ba_19693_1
Jun 06 20:11 TESTPWD_10204_file_7ckgu344_19692_1
Jun 06 20:21 TESTPWD_10204_file_7ckgu344_19692_2
Jun 06 20:22 Config_TESTPWD_10204_060609:19:10.TXT

Jul 27 19:38 TESTPWD_10204_file_77kgu17l_19687_1
Jul 27 19:40 TESTPWD_10204_file_7akgu17p_19690_1
Jul 27 19:59 TESTPWD_10204_file_79kgu17l_19689_2
Jul 27 20:05 TESTPWD_10204_file_7dkgu3ba_19693_1
Jul 27 20:11 TESTPWD_10204_file_7ckgu344_19692_1
Jul 27 20:22 Config_TESTPWD_10204_060609:19:10.TXT

Thanks for your help.

Personally, I would use the stat function to get the file date and store it into an array. Then you should be able to evaluate the newer files against the current time.

@filedata=stat($filename);
$mtime=$filedata[9]; # The tenth element is the mtime from the epoch

you mean latest file in a DIR??

ls -lrt|tail -1 

will give you latest file in that DIR

I need to get a group of latest files based on date.

Thanks for responding.

---------- Post updated at 02:45 PM ---------- Previous update was at 02:41 PM ----------

For example, I need to get all of these files based on the latest/new date

Jul 27 19:38 TESTPWD_10204_file_77kgu17l_19687_1
Jul 27 19:40 TESTPWD_10204_file_7akgu17p_19690_1
Jul 27 19:59 TESTPWD_10204_file_79kgu17l_19689_2
Jul 27 20:05 TESTPWD_10204_file_7dkgu3ba_19693_1
Jul 27 20:11 TESTPWD_10204_file_7ckgu344_19692_1
Jul 27 20:22 Config_TESTPWD_10204_060609:19:10.TXT

then use find command...

find . -mtime -1 -ls -long

vidyadhar85,

Perfect. This is the code I need.

Thank you!!!