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

  • Sounds like a question for Server Fault (serverfault.com) – RonK May 21 '11 at 20:07
  • @RonK: Could you explain why? Because it sure doesn't belong there... – Tamara 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.


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'

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 *'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy