如何防止“发现”从比当前目录更深的地方开始
我有很多目录,里面有很多文件。
我刚刚将该目录分别压缩为 filename.tar.gz
、someothername.tar.gz
等。
压缩后,我使用此 bash 删除除文件名之外的所有内容包含.tar.gz
:
<代码>查找 . ! -名称 '*.tar.gz*' | xargs rm -r
但问题是 find
会深入目录。因为目录已经被删除了,但是find
会深入各个目录,所以会显示很多信息,比如:
rm: cannot remove `./dirname/index.html': No such file or directory
那么如何防止find
深入到这个级别呢(当前目录)?
I have many directory with lots of files inside them.
I've just compressed that directory respectively become filename.tar.gz
, someothername.tar.gz
, etc.
After compressing, I use this bash to delete everything except file name contains .tar.gz
:find . ! -name '*.tar.gz*' | xargs rm -r
But the problem is find
will dive too deep inside the directory. Because the directory has been deleted but find
will dive deep in each directory, many messages displayed, such as:
rm: cannot remove `./dirname/index.html': No such file or directory
So how to prevent find
from dive deeper than this level (current directory)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
ls
代替查找
您的问题:You can use
ls
instead offind
for your problem:您可以找到要递归的最大深度:
You can tell find the max depth to recurse: