ls -lat
displays a list of all files sorted by date. When enumerated with the -l flag using the -t flag, sorts by date. If you only need the file name (possibly for a script), try something like:
ls -lat | head -2 | tail -1 | awk '{print $9}'
Here all the files will be listed, as before, get the first 2 lines (the first will look like βonly 260β), get the last (the one that shows the details of the file), and then get the 9th column that contains the file name.
source
share