linuxshellcommand-line

Get most recent file in a directory on Linux


Looking for a command that will return the single most recent file in a directory.

Not seeing a limit parameter to ls...


Solution

  • ls -Art | tail -n 1
    

    returns the latest modified file or directory.

    Flags:

    -A list all files except . and ..

    -r reverse order while sorting

    -t sort by time, newest first