linux - 如何在不保留目录结构的情况下 tar 目录?

我正在编写一个备份脚本,并且想要压缩一个文件目录:

tar czf ~/backup.tgz /home/username/drupal/sites/default/files

这会将其解压缩,但是当我解压缩生成的文件时,它包含完整的文件结构:文件位于 home/username/drupal/sites/default/files 中。

有没有办法排除父目录,以便生成的 tar 只知道最后一个目录(files)?

最佳答案

使用 --directory 选项:

 tar czf ~/backup.tgz --directory=/home/username/drupal/sites/default files 

https://stackoverflow.com/questions/5695881/

相关文章:

linux - 将 cron 选项卡设置为工作日的特定时间

python - UnicodeEncodeError : 'charmap' codec can'

python - 什么时候应该使用 Flask.g?

python - 规范化数据框的列

linux - 提取并删除目录中的所有.gz - Linux

c - 如何在C程序中列出目录中的文件?

python - 资源,客户端和 session 之间的boto3差异?

python - 如何从 Python 中的 URL 读取图像数据?

python - 在 Linux 上通过 Python 脚本截取屏幕截图

linux - 使用 Bash 按列拆分命令输出?