Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 615
  • Last Modified:

"Tar" and "Zip" UNIX files

In my UNIX operating system, I have several files and
directories in my home directory.
How can I "tar" and "zip" the contents of all the files
and directories, subdirectories, files in them together
in a file named "home.tar.zip".

Example: My home directory is: "/home/myname/"
Here are the contents:
/home/myname/>ls
dir1  dir2  file1 file2

/home/myname/dir1/>ls
dir3 file3

/home/myname/dir1/dir3/>ls
file4 file5

/home/myname/dir2/>ls
file6

How can I tar and zip all files/directories/subdirectories under "/home/myname/" and put it in a file(?) named "home.tar.zip" (From this I should be able to retrieve all the files and directories the same way they used to be before it was tar'ed and zip'ed)
thanks.
0
skundu
Asked:
skundu
1 Solution
 
griesshCommented:
tar cf - . | zip home -
is a one-liner to tar and zip the files in your current directory and underneath.
unzip -p home | tar xf -
will rebuild your directory structure and content.

Just check the man pages of zip for more options.
Anyhow, I would suggest to use the GNU version gzip, that offers a higher compression.

Good luck and don't hesitate to ask if there are problems.
======
Werner
0
 
mikeiastateCommented:
I use pack to zip files.  Just type pack <filename> <enter> from the command prompt and it compresses and puts the packed file under <filename.z>  Be sure to do this after the above mentioned tar so that you compress all data.  
0
 
PeterMacCommented:
from home directory
tar -cf home.tar .

will create tar file
then either

pack home.tar

or

compress home.tar

will create compressed file home.tar.z

both pack and compress have much better compression than zip
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
griesshCommented:
PeterMac, again, as in another question already stated:

We usually write a comment instead of an answer, so the question won't be locked and other experts have
the chance to give their opinions, too. Only if you are 150% sure that you have the right answer, we
would post it as an answer. Please take a look at "Tips on Comments and Answers" at the end of this
page.

It is also considered to be not very polite to repost comments from other experts as answers.

In addition to that is your comment about zip/compress/pack certainly not true on most UNIX systems.

skundu
please reject PeterMac's answer. At the same time it would be nice to accept one of our comments as
an answer or at least let us know if there are still any problems.

======
Werner
0
 
mikeiastateCommented:
I agree, with griessh unless you found something profoundly light shedding (and I highly doubt you did) in the answer from petermac.  Please consider the other answers.

Actually after reading the question again it seems you may have been looking more for the tar commands to get the whole tree, and not so much the zip/pack/compress info anyway.  In that case i think that griessh may have been the best answer.  

I ask griessh, could it be clarified what each flag is doing in that command.  I know that we could read the man pages, but if my second paragraph is correct, explaining what is actually getting the directory tree may get more/the points.

Correct me if I'm wrong here, but as I understand it, it goes like this.

tar cf - . | zip home -

the 'c' is not very relevent, it just means that this is a new archive and we are not adding to another.  In this case the new archive is /<current dir>/home

the 'f' means that the next arguement is where we want to write the tar'ed file to.  

in this case the following arguement is - which is the standard output.  this allows the output to sit out there waiting to be put into the next command.

the '.' means tar the current directory and it's tree structure underneath

'| zip home -' takes the standard input, (represented by the '-' and zips it into the file 'home'.  

You may want to change the work home to home.tar.zip and also cd to the myname directory before you start of course.
0
 
tfewsterCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
- Answered by griessh

Please leave any comments here before 13/1/2003

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

tfewster (I don't work here, I'm just an Expert :-)
0
 
SpideyModCommented:
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now