Unix shell scripting to find latest file having timestamp embedded...

Hi guys,

I have a directory in UNIX having files with the below format, i need to pickup the latest file having recent timestamp embedded on it, then need to rename it to a standard file name.

Below is the file format:

filename_yyyymmdd.csv, i need to pick the latest and move it with the standard file name.

Please help.

regards,

sundar

One way:

now=`date +%Y%m`
ls -rt filename_"$now"*.csv | tail | read file
cp $file standard_file_name

This looks for the last file made this month. Assuming the filename does reflect the last time the file was written to.

Please, do not duplicate posts: