linux - tar: 目录: 无法 rmdir: 目录不为空

我试图了解使用 tar 的正确方法是什么。我有一个名为 main 的目录,在 sub 目录中,它包含一些我想排除的文件和目录。我想删除的所有其他人。我使用的命令:

tar --remove-files --exclude main/sub/.runtime --exclude main/sub/.startTime --exclude main/sub/subsubdir -zcvf main.tar.gz main

但是我得到:

tar: main/sub: Cannot rmdir: Directory not empty
tar: Exiting with failure status due to previous errors

当然 main/sub 目录不是空的(因为排除了文件/目录)。在不将输出重定向到 /dev/null 或其他方式的情况下解决它的正确方法是什么?我仍然想得到错误,但不是那个错误。

最佳答案

这可能是 --remove-files 选项的错误。

您可以包含文件而不是排除文件:

#!/usr/bin/env bash

shopt -s dotglob extglob nullglob
tar -zcvf main.tar.gz main/!(sub) main/sub/!(*@(.runtime|.startTime|subsubdir))

一旦您对结果满意,请添加 --remove-files

https://stackoverflow.com/questions/62375314/

相关文章:

r - H2O 在 R 中连接失败

ios - 如何从 iOS (Swift) 连接到 MongoDB

php - 如何在 laravel 中检测 JFIF 图像类型

reactjs - WebSocket SocketIO 连接无法与 Heroku 上的 NestJ

javascript - 单击 jpg 图像时尝试使用 EXIF.js 返回 GPS 坐标

c# - 开拓者。如何在 Startup 类(方法 ConfigureServices)中获取当前

vue.js - 在 Vue 中安装不想给 $route.name

tensorflow - TensorFlow 2 和 Keras 中不同的正向和反向传播

python - 获取实例的类名

linux - docker 内部出现 fatal error : unable to access