Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I compress the contents of a folder using the tar command on an Unix system over SSH?

share|improve this question

migrated from May 21 '11 at 20:08

This question came from our site for professional and enthusiast programmers.

Sounds like a question for Server Fault ( – RonK May 21 '11 at 20:07
@RonK: Could you explain why? Because it sure doesn't belong there... – Tom Wijsman May 21 '11 at 21:32
Because that is where I post such questions :-) . Any way - this comment was added before the question was migrated. – RonK May 22 '11 at 5:08

From tar --help:

  tar -cf archive.tar foo bar  # Create archive.tar from files foo and bar.
  tar -tvf archive.tar         # List all files in archive.tar verbosely.
  tar -xf archive.tar          # Extract all files from archive.tar.

So just use tar -cf archiveName.tar folderName.

share|improve this answer

If you want to compress it, add the -z or -j arguments to the recommendations above.

ssh user@host 'tar -C direcotry -czf archivename.tar.gz files/directory'
share|improve this answer

If the content you want to archive is in the home directory of the user - it should be:

ssh login_name@hostname 'tar cvf archive-name *'

If you need to navigate somewhere, try this:

ssh login_name@hostname 'cd some-dir;tar cvf archive-name *'
share|improve this answer

You must log in to answer this question.