3

I have a folder which includes subfolders which in turn have subfolders as well. I tried:

tar --exclude='*.msh' --exclude='*.geo' -czvf cont.gz run-1/*

to compress all files and subfolders in run-1 but the files with msh and geo extensions. But tar keeps adding those files still. The files which meant to be excluded are not in run-1 but in one of the subfolders of it and I don't want to specify the locations explicitly. Where is the problem?

Edit: Below is one of the subfolders under run-1. Other subfolders have similar structure. I am also ok with excluding msh folder in all subfolders as well.

run-1
  |-np-8
      |-nmesh-3
        |-ncell-1
          |-bunch of files
          |-msh
            |-bg.msh
            |-bg.geo
Shibli
  • 133
  • 7
  • Please could you update your question with an example tree? Outline which files you want included, and which you want excluded? – Attie Oct 08 '18 at 14:59

1 Answers1

3

Try to use an exclude file containing the lines:

*.msh
*.geo

The command can then look like :

tar -czvf cont.gz -X exclude-files.txt run-1/*

You could also use the find command to create a list of files to exclude, but that only works well for a small amount of files.

harrymc
  • 455,459
  • 31
  • 526
  • 924