[英]linux: most recent file in a directory, excluding directories and . files
I would like to find the most recently changed file in a directory, excluding hidden files (the ones that start with .) and also excluding directories. 我想在目录中找到最近更改的文件,不包括隐藏文件(以。开头的文件),也不包括目录。
This question is headed in the right direction, but not exactly what I need: 这个问题朝着正确的方向发展,但不完全是我需要的:
Linux: Most recent file in a directory Linux:目录中的最新文件
The key here is to exclude directories... 这里的关键是排除目录......
Like the answer there except without -A 就像那里的答案一样,除非没有-A
ls -rt | tail -n 1
Look at man ls
for more info. 查看
man ls
获取更多信息。
To make it exclude directories, we use the -F option to add a "/" to each directory, and then filter for those that don't have the "/": 为了使它排除目录,我们使用-F选项向每个目录添加“/”,然后过滤那些没有“/”的目录:
ls -Frt | grep "[^/]$" | tail -n 1
这样做你想要的,不包括目录:
stat --printf='%F %Y %n\n' * | sort | grep -v ^directory | head -n 1
same one, not very clean but: ls -c1
+ tail if you want => ls -c1 | tail -1
同一个,不是很干净但是:
ls -c1
+ tail如果你想要=> ls -c1 | tail -1
ls -c1 | tail -1
$ touch a .b
$ ls -c1
a
$ ls -c1a
a
.b
$ touch d
$ ls -c1
d
a
$ ls -c1a
.
d
a
.b
..
$ touch .b
$ ls -c1a
.b
.
d
a
..
As you can see, without a
arg, only visible files are listed. 正如你所看到的,没有
a
ARG,唯一可见的文件中列出。
可能与其他帖子中的答案相同,但差异很小(不包括目录) -
ls --group-directories-first -rt | tail -n 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.