linux - 当我使用路径压缩 tar gz 文件时,文件夹会被包含在内

标签 linux shell terminal redhat tar

当我使用路径压缩 tar gz 文件时,文件夹会被包含在内。但是,我只想压缩文件。这是我尝试过的:

$ tar -czf ../coolfile.tar.gz newfol/coolfile

当我解压缩这个 tar.gz 时,我得到 coolfile文件位于 newfol 文件夹中。我想要压缩coolfile仅有的。

解压缩 tar gz 命令:

$ tar -xvf coolfile.tar.gz`

最佳答案

tar -C newfol -cvzf coolfile.tar.gz coolfile

注意:您指定相对于当前目录的 tar.gz 文件,并指定相对于 -C 选项参数的目录要压缩的文件,并且该 tar 将 cd 进入以执行 tar。

关于linux - 当我使用路径压缩 tar gz 文件时,文件夹会被包含在内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56979915/

相关文章:

linux - 从 bash 中的一行读取表格数据

php无法无错误上传大文件

shell - 使用 cURL 登录 Stack Overflow

java - 新定义的环境变量在 WSL2 之外看不到?

javascript - 如何检测是否在新的 Windows 终端中运行?

php - 执行 Linux shell 脚本时出错

linux - linux i686 上的 current_task 是什么?

shell - 运行脚本以响应错误发生

c++ - Visual Studio Code 集成终端不显示文本

macos - flutter 医生 : ERROR: Could not connect to lockdownd, 错误代码 -21