Is it possible to create a symlink to the latest file in a directory?

后端 未结 1 887
刺人心
刺人心 2021-02-02 17:31

I have a home directory in my unix box. I would like to setup a number or shortcuts in it to point to the latest file in another directory and the link will update if a newer fi

1条回答
  •  情书的邮戳
    2021-02-02 17:41

    In bash, this will make a link to the latest file or directory in "target-directory" called "latest":

    ln -s target-directory/`ls -rt target-directory | tail -n1` latest
    

    And this will wait for a change in "target-directory" before returning:

    inotifywait -e attrib target-directory
    

    0 讨论(0)
提交回复
热议问题