Stack Exchange network consists of 176 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
How do I compress the contents of a folder using the tar command on an Unix system over SSH?
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.
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 *'
Required, but never shown