我是unix的新手,在其他问题上无法获得适当的结果.
我想只列出当前目录中超过x天的文件.我有以下限制
file1 file2 file3 ..我用过find . -mtime +30.但这也会在子目录中提供文件和文件.我想限制递归搜索,而不是搜索内部目录.
非常感谢提前!
A1r*_*Pun 14
添加@Richasantos的答案:
这工作得很好
$ find . -maxdepth 1 -type f -mtime +30
Run Code Online (Sandbox Code Playgroud)
印刷:
./file1
./file2
./file3
Run Code Online (Sandbox Code Playgroud)
您现在可以将其传递给您想要的任何内容。假设您要删除所有这些旧文件:
$ find . -maxdepth 1 -type f -mtime +30 -print | xargs /bin/rm -f
Run Code Online (Sandbox Code Playgroud)
来自man find:``
如果您将 find 的输出通过管道传输到另一个程序中,并且您正在搜索的文件极有可能包含换行符,那么您应该认真考虑使用该
-print0选项而不是
所以使用-print0
$ find . -maxdepth 1 -type f -mtime +30 -print0
Run Code Online (Sandbox Code Playgroud)
打印(中间有空字符):
./file1./file2./file3
Run Code Online (Sandbox Code Playgroud)
并像这样使用来删除那些旧文件:
$ find . -maxdepth 1 -type f -mtime +30 -print0 | xargs -0 /bin/rm -f
Run Code Online (Sandbox Code Playgroud)
你可以这样做:
find ./ -maxdepth 1 -type f -mtime +30 -print
Run Code Online (Sandbox Code Playgroud)
如果遇到问题,请:
find ./ -depth 1 -type f -mtime +30 -print
Run Code Online (Sandbox Code Playgroud)