Shell – tar – exclude does not work

shell-scriptsolaristar

I've supposed to archive a directory with tar and exclude some files. I have a directory $HOME/java which includes some .java and .class files. What I want to do is exclude all .class files using the -X exclude option.

I've created an Exclude file by using find

$ find $HOME/java -name "*.class" > Exclude

Then tried to archive the directory

$ tar -cvfX java.tar Exclude $HOME/java

But somehow it does not do the exclude. The tar version on Solaris does not support exclusion by name.

Best Answer

 tar -cvf java.tar --exclude="*.class" $HOME/java

From the man pages:

--exclude pattern

    Do not process files or directories that match the specified pattern.  
    Note that exclusions take precedence over patterns or filenames 
    specified on the command line.
Related Question