0

I have a couple of files in a folder such as abc_2-01-2019.csv, abc_2-02-2019.csv, abc_2-03-2019.csv, abc_2-04-2019.csv, and I want to pick the latest file and send it over an email as an attachment on Linux VM. Can anybody help me out?

1
  • latest file - according to creation date? modification date?
    – KamilCuk
    Commented Feb 26, 2019 at 22:50

1 Answer 1

1
ls -Art | tail -n 1

where

 -A  do not include . and ..
 -t sort by modification time
 -r reverse sort

and tail -n 1 gets last entry

1
  • but that folder also contains other files than required CSVs. I want to choose latest csv with name abc_latest_date.csv Commented Feb 28, 2019 at 13:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.