1

I am trying to create a .tar file of the filesystem but exclude the /proc directory.

The command I have tried is:

tar -czvf mytar.tgz / --exclude='/proc'

But this does not exclude the directory.

I have also tried it without the single quotes.

# tar --version
tar (GNU tar) 1.31

How can I exclude the directory?

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
Proletariat
  • 669
  • 3
  • 16
  • 28
  • 1
    Are you trying to create a backup? If yes, this is probably not a good approach. – Panki Mar 31 '21 at 08:55
  • 1
    Did you get any form of diagnostic messages from that `tar` command, like `The following options were used after any non-optional arguments in archive create or update mode. These options are positional and affect only arguments that follow them. Please, rearrange them properly.` See also the `--one-file-system` option for GNU `tar`. Also consider using backup software for doing backups, like `restic` or `borgbackup`. – Kusalananda Mar 31 '21 at 09:09

1 Answers1

3

I agree with the comment about this not being the best approach but just in terms of answering your issue - your version of tar requires that the --exclude options have to be placed at the beginning of the tar command.

See: https://stackoverflow.com/q/984204

tar --exclude='/proc' -czvf mytar.tgz / 
Pobtastic
  • 146
  • 4