How do I compress the contents of a folder using 'tar' over SSH?
Solution 1
From tar --help
:
Examples:
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
.
Solution 2
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'
Solution 3
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 *'
Related videos on Youtube
Tamara Wijsman
In my free time I visit Stack Exchange to help out people with their questions and help maintain the community. Located in Belgium, I have studied Computer Science at the University of Antwerp and became a Master in Software Engineering. When I think a post can be improved I will try to do so by fixing grammatical or spelling errors, clarifying meaning without changing it, correcting minor mistakes, adding related resources or links. For the less obvious things of those I will leave a note in the edit, click on the date to see this. I will only edit content in posts once, and let the author or other users be free to choose to rollback; when there are opposing views, we can raise this to meta to let the majority decide which revision of the post they want. This will be done with respect of the original author and when I'm sure enough that it would only improve the post. Have a nice day! :)
Updated on September 18, 2022Comments
-
Tamara Wijsman over 1 year
How do I compress the contents of a folder using the
tar
command on an Unix system over SSH?-
RonK almost 13 yearsSounds like a question for Server Fault (serverfault.com)
-
Tamara Wijsman almost 13 years@RonK: Could you explain why? Because it sure doesn't belong there...
-
RonK almost 13 yearsBecause that is where I post such questions :-) . Any way - this comment was added before the question was migrated.
-