Get the newest file based on timestamp

前端 未结 7 2021
半阙折子戏
半阙折子戏 2020-12-15 12:00

I am new to shell scripting so i need some help need how to go about with this problem.

I have a directory which contains files in the following format. The files a

7条回答
  •  醉酒成梦
    2020-12-15 12:27

    My solution to this is similar to others, but a little simpler.

    ls -tr | tail -1
    

    What is actually does is to rely on ls to sort the output, then uses tail to get the last listed file name.

    This solution will not work if the filename you require has a leading dot (e.g. .profile).

    This solution does work if the file name contains a space.

提交回复
热议问题