Solved

"Tar" and "Zip" UNIX files

Posted on 2001-06-12
7
484 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Host issue and need to move VM's 2 282
Cygwin VIM in WIndows 2007: Unable to copy text to Windows 10 65
Unix Script: Loop over all days of a month 17 99
aix unix tar error 3 68
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…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

825 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