简体   繁体   English

Bash ,查找最近 x 天的修改过的文件

[英]Bash , Find modified files for the last x days

Is there a way to find all files that have been modified the last x days from a specific directory?有没有办法从特定目录中找到过去 x 天修改过的所有文件? I have done this我已经这样做了

find /home/user -iname "*.txt" -mtime -$x -print but it shows the files from user not from the directory. find /home/user -iname "*.txt" -mtime -$x -print但它显示来自用户的文件而不是来自目录的文件。

the content of the directory is:目录内容为:

total 8
-rw------- 1 danae danae    0 Jun 21 22:08 a
dr-x------ 2 danae danae 4096 Jun 30 10:56 d
-rw------- 1 danae danae    0 Jun 30 10:56 file
-rw-rw---- 1 danae danae    8 Jun 29 13:03 file2
-rw-rw---- 1 danae danae    0 Jun 21 22:06 file3
-rwxrwx--x 1 danae danae    0 Jun 21 22:06 file4
-r-------- 1 danae danae    0 Jun 21 22:07 file5
-rw-rw-r-- 1 danae danae    0 Jun 21 22:07 file6

The issue with your current command您当前命令的问题

find /home/user -iname "*.txt" -mtime -$x -print

Is "/home/user" which is telling find to always look in that directory.是“/home/user”,它告诉 find 总是在该目录中查找。

This should be replaced with the directory you want to look in. Or if you are doing this within a bash script first cd to the directory and then use这应该替换为您要查看的目录。或者,如果您在 bash 脚本中执行此操作,请首先cd到该目录,然后使用

find . -iname "*.txt" -mtime -$x -print

Use .采用 。 to indicate the current directory:指示当前目录:

find . -iname "*.txt" -mtime -$x -print

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 查找过去 x 天内未访问的文件 - Find files that were not accessed in the last x days 如何查找最近10天修改过的10个最大目录,并使用Bash对其进行排序 - How to find the 10 biggest directories modified in the last 10 days and sort them using Bash 最近 2 天内修改过的 tar 文件 - Tar files that were modified in the last 2 days 如何删除具有X天有效期(而不是最后修改)的文件。 可能吗 的Linux - How to delete files which have X days lifetime, not last modified. Is it even possible. Linux 查找上次修改时间为 8 月的文件 - Find files last modified in August logrotate - 压缩文件修改x天数 - logrotate - compression files modified x number of days 我试图在 Linux 中查找过去 10 天内创建或修改的最大文件 - im trying to find the largest files created or modified within the last 10 days within Linux 如何找到最近10天内被修改但不在bash终端上的“ CVS”,“ build”或“ classes”文件夹中的文件? - How do I locate files which were modified within the last 10 days but and NOT in a “CVS”, “build” or “classes” folder on a bash terminal? 如何查找最近x分钟内修改的文件(查找-mmin不能按预期工作) - How to find files modified in last x minutes (find -mmin does not work as expected) Bash 脚本查找包含修改文件的目录 - Bash script find directories with modified files in it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM