Ubuntu – Using LS To Show The Date Modified And A Specific Number Of Files

14.04command line

I am using ls -t | head -8 to show the last 8 files modified in a directory, but this only prints the file name.

Is there a way to alter the above command so that it shows the modified date for the file names as well?

Best Answer

You'll want to use stat to get the file metadata:

stat -c $'%y\t%n' * | sort -n | head -8