Get most recent file in a directory on Linux
ls -Art | tail -n 1
Not very elegant, but it works.
Used flags:
-A
list all files except .
and ..
-r
reverse order while sorting
-t
sort by time, newest first
ls -t | head -n1
This command actually gives the latest modified file in the current working directory.
This is a recursive version (i.e. it finds the most recently updated file in a certain directory or any of its subdirectory)
find $DIR -type f -printf "%T@ %p\n" | sort -n | cut -d' ' -f 2- | tail -n 1
Edit: use -f 2-
instead of -f 2
as suggested by Kevin