Solved

"Tar" and "Zip" UNIX files

Posted on 2001-06-12
7
468 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
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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 20

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

706 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now