I am trying to make a tar archive of all files in my /var directory. Naturally, I want to exclude the Unix sockets in there.

So I try a command that looks something like:

sudo find /var \! -type s -exec tar -rf ~/test/etc.tar {} \;

But this throws up the repeated error message

tar format cannot archive socket:

When I try to do a copy instead of tar, I get a similar error:

cp: ./var/run/devd.pipe is a socket (not copied).

Does anyone have an idea why find fails to exclude files of type socket? It is able to exclude, for instance, files of type directory..

  • TAR implementations typically do not try to achive file types they cannot archive with the selected archive format. So what is your problem?
    – schily
    Commented Mar 21, 2019 at 14:31

1 Answer 1


You will have to exclude directories as well. If not excluding directories, tar will get /var (and other directories) as argument, and will proceed to archive these with all contents (sockets or not). It will additionally add multiple copies of many of the files due to the same reason (/var includes /var/log/messages and so does /var/log).

find /var ! -type s ! -type d -exec tar -r -f archive.tar {} +

Or, if you just want regular files and symbolic links:

find /var '(' -type f -o -type l ')' -exec tar -r -f archive.tar {} +

I've chosen to use -exec ... {} + here instead of -exec ... {} ';' as we probably want to call tar as few times as possible with as many arguments as possible at a time.

  • Thanks for explaining it and the extra tip. Two followup questions: (why) don't you need to escape the exclamation marks? What does the option -o do? I don't seem to have it in my (BSD) man pages but only in the examples...
    – ahron
    Commented Nov 26, 2018 at 11:39
  • 1
    @Yogesch If you use a sh shell (like bash or ksh), then a lone ! is not special in any way and does not need to be quoted. The -o option means "OR" (-a, "AND", is the default between two tests). The find manual will mention these operators for sure (it does on OpenBSD).
    – Kusalananda
    Commented Nov 26, 2018 at 11:43
  • Okay. It isn't mentioned in the FreeBSD man pages but, I checked the again and there is an operators section which has -and and -or, not the abbreviated forms. Same thing I guess. Thanks a lot for helping out :-)
    – ahron
    Commented Nov 26, 2018 at 11:48
  • 1
    @Yogesch The equivalence is mentioned in the "STANDARDS" section of the FreeBSD manual. The short variant of these operators is the standard one.
    – Kusalananda
    Commented Nov 26, 2018 at 11:53
  • Yes, indeed it is. Never knew there was still useful information after the examples. should read the man page till the end...
    – ahron
    Commented Nov 26, 2018 at 11:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .