---
title: "Linux tar压缩时排除某个目录或文件的参数"
author: "congjl2002"
date: "2012-05-03T08:58:08Z"
tags: []
categories: ["操作系统"]
slug: "linux-tar"
draft: false
lastmod: "2012-05-03T08:58:08Z"
id: 1508280
url: "https://congjl2002.iteye.com/blog/1508280"
---

在对某个目录进行压缩的时候，有时候想排除掉某个目录，例如：

如果123目录下有3个子目录，aa、bb、cc。

我现在想只对aa和bb目录打包压缩，命令如下：

`tar -zcvf 123.tar.gz --exclude=cc 123`  
（在123目录的外面运行）

使用exclude参数来过滤不需要的目录或文件，排除某个文件的操作和目录一样。

[转自](http://www.ha97.com/4024.html "（总结）Linux tar压缩时排除某个目录或文件的参数") : http://www.ha97.com/4024.html