文件列表

问题描述 投票:2回答:2

我想列出最后1小时的文件,其中包含.sh扩展名。我目前正在使用以下内容:

ls -l *.sh | find "/root/" -mmin -60 | awk '{print $9}'

但是,此命令无法按预期工作。

谁能帮我?先感谢您。

linux bash shell unix
2个回答
3
投票

您可以使用find命令执行此操作:

find <DIR> -type f -name '*.sh' -mmin -60

要么

find <DIR> -type f -name '*.sh' -mmin -60 -executable

说明:

  1. <DIR>是您要搜索的目标目录
  2. -type f强行寻找文件
  3. -name '*.sh'查找带有sh扩展名的文件
  4. -mmin -60查找在不到1小时内修改过的文件
  5. -executable如果要添加文件具有执行权限的约束。
  6. -maxdepth 1只查看文件夹中的文件或使用更高的深度,如果你想看到N级别。你命令变成:find <DIR> -maxdepth 1 -type f -name '*.sh' -mmin -60 -executable

1
投票

你的意思是:

find . -name "*.sh" -mmin -60 -ls | awk '{print $9}'
1
1

然后9美元给了我一个月的那一天。

类似的结果是可能的,纯粹通过gnu-find:

find . -name "*.sh" -mmin -60 -printf "%Ad\n"
01
01

除了前导零。有3个日期可能:

%Ak    File's last access time in the format specified by k, which is either `@' or a directive for the C `strftime' function.  The possible values for k
                 are listed below; some of them might not be available on all systems, due to differences in `strftime' between systems.
%Ck    File's last status change time in the format specified by k, which is the same as for %A.
%Tk    File's last modification time in the format specified by k, which is the same as for %A.

(来自gnu-find的手册页)。

© www.soinside.com 2019 - 2024. All rights reserved.