如何防止“发现”从比当前目录更深的地方开始

发布于 2024-10-09 03:59:51 字数 453 浏览 1 评论 0原文

我有很多目录,里面有很多文件。

我刚刚将该目录分别压缩为 filename.tar.gzsomeothername.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧故 2024-10-16 03:59:51

您可以使用 ls 代替 查找您的问题:

ls | grep -v .tar.gz | xargs rm -rf

You can use ls instead of find for your problem:

ls | grep -v .tar.gz | xargs rm -rf
云醉月微眠 2024-10-16 03:59:51

您可以找到要递归的最大深度:

find -maxdepth 1 ....

You can tell find the max depth to recurse:

find -maxdepth 1 ....
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文