【发布时间】:2014-10-28 02:20:58
【问题描述】:
我在linux上,我想知道如何在目录中找到最新的可执行文件? 我已经知道如何找到最新的:
ls -rt1 | tail -1
但是如何过滤掉可执行文件呢?
编辑: 我找到了解决方案:
find path/to/dir/myfile* -perm /u=x,g=x,o=x -mtime 0 | tail -1
这是存档吗?还是有更好的解决方案??
【问题讨论】:
我在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" "
【讨论】:
find . 替换为find /your/dir。