Solved

"Tar" and "Zip" UNIX files

Posted on 2001-06-11
4
4,473 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
4 Comments
 

Accepted Solution

by:
saila earned 50 total points
ID: 6179213
In AIX you can tar the files using the tar command
and zip it using the compress command

for your problem

in /home/mydir give the command as

/home/mydir> tar -cvf nameoftarfile.tar .
when you give a dot (.) at the end then all the dir from the current dir and all the susbequent dirs will be tared

now to compress it just say

/home/mydir>compress nameoftarfile.tar
the file will be now be "nameoftarfile.tar.Z"


now you can move the compressed file to the  m/c you want and create a home/mydir
you can get all you files back as you had before

/home/mydir> zcat nameoftarfile.tar.Z | tar -xvf -

or

/home/mydir>uncompress nameoftarfile.tar.Z
and then
/home/mydir>tar -xvf nameoffile.tar

The difference between using zcat and uncompress etc.. is that when you zcat then you'll have the compressed file, bu twith uncompress you will be left with tar file and you need to compress it again to move
so choice is yours


But one more suggestion, before doing all this check if you having enough space in the filesystem or else the commands will fail

hope this helps







0
 
LVL 38

Expert Comment

by:yuzh
ID: 6179671
Hi  saila ,

     Here's what you can do tp make a tar ball, of your home dir:
     (I assume you login as yourself)

     1. cd ~
      2. tar cvf backup.tar .
      where . means that the current dir, you can replace . with the file, dirs you want to put in, eg:

      tar cvf backup.tar file1 file2 ... dir1 dir2

     To make a compress file of the tar ball, you have a lot of options:
      1. use the compress command:
          compress backup.tar
          this will create a compress file named: backup.tar.Z.
          and you use uncompress command to uncompress it

       2. use the zip command: (create a backup.tar.zip file)
           zip backup.tar.zip backup.tar
           use unzip to unzip the file

        3. if you have gzip install on your systems:
           gzip backup.tar
            this will create backup.tar.gz file
           and you use gunzip to unzip it.

      Note: 1, and 3, will autodelete the backup.tar file after the .Z or .gz file is created. 2 will leave the backup.tar alone.

      In some of the UNIX system, you might have to create you tar ball
out side your home dir:
      tar cvf /tmp/backup.tar .
      mv /tmp/backup.tar .


     I hope this can help.

Regards
    yuzh
         
0
 
LVL 2

Expert Comment

by:mhonomichl
ID: 6181269
One of the easiest ways I have found is to use gzip and GNU tar.  You can download both at www.sunfreeware.com.  One you have these installed, you can type this command:

tar -zcvf home.tgz

With GNU tar, the -z option is added to automatically gzip the files when it creates the tarball.  It just makes for less commands, as the other suggestions above are just as good.


Mark

NOTE: Even if you are not using solaris, www.sunfreeware.com has the sourcecode also.  You can also check sites related to your specific flavor.
0
 

Author Comment

by:skundu
ID: 6338903
Thanks a lot everybody...
skundu
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
UNiX Script filesystem space usage 19 67
NTP Server in VMware 5 160
How to clone solaris 10 machine 33 111
How can i set a Environment Variable in my Unix script ? 3 47
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
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…

914 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

17 Experts available now in Live!

Get 1:1 Help Now