转自:用 tar 打包目录时排除某一个子目录的方法

 

在我们需要对网站进行备份、迁移时需要对网页目录进行打包备份。但有时候网站中的某个子目录由于种种原因不需要备份(过大,临时文件 等等)。此时通过tar命令,加入 exclude 参数就可以实现这样的目标。

具体的命令如下:

tar cfz hosteguide.com.tar.gz /var/www/hosteguide.com/ --exclude=var/www/hosteguide.com/files/dontneed

如果需要排除多个子目录,那么就执行

tar cfz hosteguide.com.tar.gz /var/www/hosteguide.com/ --exclude=var/www/hosteguide.com/files/dontneed --exclude /var/www/hosteguide.com/files/dontneed2

而如果主机的 tar 是 GNU 的版本,exclude 参数就要放在前面了:

tar cfz hosteguide.com.tar.gz --exclude=/var/www/hosteguide.com/files/dontneed /var/www/hosteguide.com

注意 --exclude后面的排除目录后不能带/ ,否则不起作用。

相关文章:

  • 2021-12-17
  • 2021-07-28
  • 2021-12-31
  • 2021-06-26
  • 2022-12-23
  • 2021-07-06
猜你喜欢
  • 2021-09-24
  • 2022-12-23
  • 2021-06-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案