tar the entire directory except one directory

Hi All,

I need to tar the entire directory except one directory inside that.
I have used the below command

tar -cvfX test.tar bin/perl bin/

I need to tar all the directories inside the bindirectory except the perl directory

Please help me in solving this :b:

Regards,
Kalai

If you are using the GNU version of tar utility, then you may use the "--exclude" option of this command.

tyler_durden

tar -cvfX test.tar bin/ --exclude bin/perl
its not working.
Please provide me the syntax of it

Let me guess, you're getting an error like

tar: test.tar: Cannot stat: No such file or directory

and there's suddenly a file named 'X' in the current directory?

You've mixed up the order of the option switches. '-f' takes the next argument to be the name of the file where it should tar into, in your case 'X'. If you want to use the -X switch, you should provide a file with the patters you want to exclude. So the correct syntax should probably be:

tar -cvf test.tar --exclude bin/perl bin/

Thanks for your information.
tar -cvf test.tar --exclude bin/perl bin/
When i execute i am getting the below error
tar: --exclude: No such file or directory

---------- Post updated at 01:22 AM ---------- Previous update was at 12:34 AM ----------

I got a solution.
Put the excluded file or directory name in some temporary file (/tmp/test)

then execute tar -cvfX test.tar /tmptest *

Thanks All :slight_smile: