如何创建仅包含文件而不包含文件目录的tarball?

问题描述

我有一个包含3个文件文件夹foo。 如何创建仅包含文件的压缩包。而不是用这三个文件的foo /。使用终端。
感谢您的帮助。

解决方法

使用bash和GNU tar:

shopt -s dotglob
cd /path/to/foo && tar -cvf /tmp/file.tar -- *

来自man bash

dotglob:如果已设置,则bash包含以“。”开头的文件名。扩展路径的结果。