Search code examples
linuxbashubuntufedora

How to see last created 3 files in a directory without passing date parameters


How to list the last three new files. it should be sorted on the basis of the lat created status?.


Solution

  • You can use following

    $ ls -rt /tmp/ | tail -3

    ls will list all the files -r reverse order while sorting -t sort by modification time, newest first

    tail will show you 10 lines by default from last -n, --lines=K output the last K lines, instead of the last 10; or use -n +K to output starting with the Kth