gpt4 book ai didi

linux - 如何查找目录中最新的可执行文件

转载 作者:太空宇宙 更新时间:2023-11-04 05:03:23 26 4
gpt4 key购买 nike

我使用的是 Linux,我想知道如何在目录中查找最新的可执行文件?我已经知道如何找到最新的:

ls -rt1 | tail -1

但是如何过滤掉可执行文件呢?

<小时/>

编辑:我找到了解决方案:

find path/to/dir/myfile* -perm /u=x,g=x,o=x -mtime 0 | tail -1

这是保存吗?或者有更好的解决方案吗?

最佳答案

给出基本的 find 命令来查找从当前目录开始的文件:

find . -type f

让我们添加功能:

  • 要查找可执行文件,您可以使用 -executable 选项:

    find . -type f -executable
  • 要仅在一级深度(即不在子目录中查找),请使用 -maxdepth 1 选项:

    find . -maxdepth 1 -type f
  • 要查找目录中最后修改的文件,您可以使用 How to recursively find the latest modified file in a directory? :

    find . -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" "

总而言之,这会在一级深度中查找最后修改的可执行文件:

find . -maxdepth 1 -type f -executable -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" "

关于linux - 如何查找目录中最新的可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25646755/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com