是否可以创建指向目录中最新文件的符号链接? [英] Is it possible to create a symlink to the latest file in a directory?

查看:33
本文介绍了是否可以创建指向目录中最新文件的符号链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 unix 框中有一个主目录.我想在其中设置一个数字或快捷方式以指向另一个目录中的最新文件,如果创建了新文件,链接将更新.

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.

这可能吗?

到目前为止,我能够获得最新的文件:

So far I able to get the latest file:

ls -lrt | tail -n1

谢谢

也许我什至可以创建一个 shell 而不是一个软链接来查找最新的文件并返回它,以便我可以打开/grep/delete 等?

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?

推荐答案

在 bash 中,这将链接到名为latest"的target-directory"中的最新文件或目录:

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

这篇关于是否可以创建指向目录中最新文件的符号链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆