Rename The Latest File

i need to get the latest file based on timestamp. assuming that i have the following files:

$ ls -latr
total 40
drwxr-sr-x    6 pcrdftdv pcrdgrp         512 Jun 30 12:53 ..
-rwxrwxrwx    1 pcrdftdv pcrdgrp           6 Jul 07 13:35 sample1.csv
-rwxr-xr-x    1 pcrdftdv pcrdgrp           6 Jul 07 14:14 sample2.scv
-rwxr-xr-x    1 pcrdftdv pcrdgrp           6 Jul 07 14:15 sample3.csv
drwxr-sr-x    2 pcrdftdv pcrdgrp         512 Jul 07 14:15 .
$

in the example above the file sample3.csv is the last or latest that was created. how can i get the latest file and rename it to PCARDEXPT file? thanks.

ls -1t *.csv | head -1 | xargs -I{} mv {} PCARDEXPT

that works thanks so much.

Just be careful: if you run it multiple times, you lose the newest file :slight_smile: