ssh [email protected] tar cvpf - /root/1 > /home/user/arc.tar.gz

need add


i try and not work:

ssh [email protected] tar cvpf - /root/1 > /home/user/arc.tar.gz --exclude=/root/1/2
  • 3
    Can you say in what way your command did not work? Did you, for example, get any specific error messages? What Unix is running on the remote system, and what implementation of tar does it have?
    – Kusalananda
    Aug 28, 2023 at 18:29
  • Please add a bit of context to your question. Until then, it will be marked as Closed, although I see a very well written answer.
    – eyoung100
    Dec 14, 2023 at 19:17

1 Answer 1


GNU tar reports exactly what's going on. Since you are using --exclude can I assume that is the version you're using? If so, please read what it told you:

tar: The following options were used after non-option arguments.  These options are positional and affect only arguments that follow them.  Please, rearrange them properly.
tar: --exclude ‘/root/1/2’ has no effect
tar: Exiting with failure status due to previous errors

This error message should have been in your question as it's highly relevant.

The solution is to rearrange the arguments properly:

tar cvpf - --exclude=/root/1/2 /root/1 > /home/user/arc.tar.gz 

I note that you're writing to a file that implies it contains gzip-compressed data but that actually does not (you don't tell tar to generate a compressed output stream):

file /home/user/arc.tar.gz
/home/user/arc.tar.gz: POSIX tar archive (GNU)

Here is the resulting corrected command in full:

ssh [email protected] tar czvpf - --exclude=/root/1/2 /root/1 >/home/user/arc.tar.gz 

file /home/user/arc.tar.gz
/home/user/arc.tar.gz: gzip compressed data, from Unix, original size modulo 2^32 …123456…

You must log in to answer this question.

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