-1

I'm creating a tarball of a large codebase managed in ClearCase. Every directory has a sub-directory named ".CC". I'd like to exclude these from my tarball.

I've found Excluding directory when creating a .tar.gz file, but excluding that would appear to require passing each and every .CC directory on the commndline. This is impractical in my case.

Is there a way to exclude directories that meet a particular pattern?

EDIT: I am not asking how to exclude a specific finite list of directories. I am asking how to exclude all directories that end in a particular pattern.

Elros
  • 263
  • 2
  • 9
  • Possible duplicate of [Shell command to tar directory excluding certain files/folders](https://stackoverflow.com/questions/984204/shell-command-to-tar-directory-excluding-certain-files-folders) – tripleee Sep 14 '17 at 04:39

2 Answers2

1

Instead of manually typing --exclude 'root/a/.CC' --exclude 'root/b/.CC' ... you can type $(find root -type d -name .CC -exec echo "--exclude \'{}\'" \;|xargs)

You can use whatever patterns find supports, or even use something like grep inbetween find and xargs.

Marcus Sundman
  • 124
  • 1
  • 5
0

The following bash script should do the trick. It uses the answer given by @Marcus Sundman.

#!/bin/bash

echo -n "Please enter the name of the tar file you wish to create with out extension "
read nam

echo -n "Please enter the path to the directories to tar "
read pathin

echo tar -czvf $nam.tar.gz
excludes=`find $pathin -iname "*.CC" -exec echo "--exclude \'{}\'" \;|xargs`
echo $pathin

echo tar -czvf $nam.tar.gz $excludes $pathin

This will print out the command you need and you can just copy and paste it back in. There is probably a more elegant way to provide it directly to the command line.

*.CC could be exchanged for any other common extension and this should still work.

James
  • 223
  • 3
  • 8