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

左心房为你撑大大i 提交于 2020-05-09 19:23:07

问题


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 file is created.

Is this possible?

So far I able to get the latest file:

ls -lrt | tail -n1

Thanks

[EDIT]

Perhaps I could even create a shell instead of a softlink which finds the latest file and returns it so I can open/grep/delete etc?


回答1:


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


来源:https://stackoverflow.com/questions/10626120/is-it-possible-to-create-a-symlink-to-the-latest-file-in-a-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!