Solved

"Tar" and "Zip" UNIX files

Posted on 2001-06-12
7
516 Views
Last Modified: 2013-12-06
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
Comment
Question by:skundu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 11

Accepted Solution

by:
griessh earned 50 total points
ID: 6183486
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
 

Expert Comment

by:mikeiastate
ID: 6188459
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
 
LVL 9

Expert Comment

by:PeterMac
ID: 6413744
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:griessh
ID: 6414000
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
 

Expert Comment

by:mikeiastate
ID: 6414332
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
 
LVL 21

Expert Comment

by:tfewster
ID: 7621338
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
 

Expert Comment

by:SpideyMod
ID: 7805210
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CPU monthly average? 12 139
unix scripting question 1 115
Unix Question 19 53
Oracle Finace 3 96
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question