Find latest file in a directory methods

Sometimes there are so many files in a directory that it’s hard to find the last file in the directory. We show you here 2 ways for finding it out.

With awk we print the last argument of the last line:

$ ls -lrt | awk '{ f=$NF }; END{ print f }'

Reverse ordering with ls and then getting the first line:

$ ls -t1 | head -n1


Posted

in

by

Tags:

Comments

Leave a Reply