World is Welcome To The World of Linux

Journey into the world of linux

Menu
  • About
  • Welcome
Menu

Ways To Zip The Directory Structure of Unix

Posted on April 7, 2009 by Ganesh Sharma

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

Often its the requirement of system administrators to move the directories in between the servers. Also the confusion arises which utility to use for the best results. Normally zip, tar, cpio utilities are used the most. I’m writing a short introduction of zip and tar.

Let’s take an example directory: example. The files and directories are shown as below:

ganesh@ganesh-desktop:~$ ls example/

a  b  c  d  e  f  g  h

The Zip Method

To create the zip file named example.zip, you can use the following command:

zip -r example.zip example

The -r option specifies to move recursively the directory structure of the directory example.

ganesh@ganesh-desktop:~$ zip -r example.zip example/

adding: example/ (stored 0%)
adding: example/d (stored 0%)
adding: example/e (stored 0%)
adding: example/f (stored 0%)
adding: example/c/ (stored 0%)
adding: example/c/d (stored 0%)
adding: example/c/l (stored 0%)
adding: example/c/e (stored 0%)
adding: example/c/g (stored 0%)
adding: example/c/a (stored 0%)
adding: example/b/ (stored 0%)
adding: example/b/w (stored 0%)
adding: example/b/k (stored 0%)
adding: example/b/c (stored 0%)
adding: example/g (stored 0%)
adding: example/h (stored 0%)
adding: example/a/ (stored 0%)
adding: example/a/l (stored 0%)
adding: example/a/k (stored 0%)
adding: example/a/m (stored 0%)

The tar command
The tar command has been my all time favourite. Also once you get used to it, you won’t find it difficult to use it. Here are few uses to it.

  1. You can view the contents of archive without untarring the archive.
  2. You can retain the permissions.
  3. You can retain the directory structures.
  4. You have the facility to exclude files.
  5. You can create the archive and zip/gzip/bzip it on the fly.
  6. And so on…..

Here are examples:

tar cvf example.tar example
c: Means create the archive.
v: Means verbose.(v is small)
f: Means create the file archive as named.

At the end you’ll name the directory to be archived.

ganesh@ganesh-desktop:~$ tar cvf example.tar example/
example/
example/d
example/e
example/f
example/c/
example/c/d
example/c/l
example/c/e
example/c/g
example/c/a
example/b/
example/b/w
example/b/k
example/b/c
example/g
example/h
example/a/
example/a/l
example/a/k
example/a/m

ganesh@ganesh-desktop:~$ ls example.tar
example.tar

Let’s say you want to gzip the archive as well:

You can run:
tar czvf example.tgz example
z: stands for gzip archive format.

Now let’s say you want to gzip the archive:

You can run:
tar cjfv example.tar.bz example
j: stands for bzip archive format.

Now, let’s say you want to archive a directory. You want to have same permissions as at present, same directory path values(absolute paths) then you’ll use:

ganesh@ganesh-desktop:~$ tar -pPczvf example1.tgz example
-p: Permssions should not change.
-P: The Pathes should not change. Means don’t remove starting / from the file names.

Now restoring files from the archive.


Restoring from zip archive:
unzip zippedarchivename.zip

Restoring from tar archive:

  1. If the archive is tgz format then:tar xvfz example.tgz
  2. If the archive is bz format then:tar xvfj example.tar.bz
  3. If its simple archive thentar xvf example.tar
  4. If you just want to view the archive then use -t option.tar tvfj example.tar.bz

That’s all for this session. Keeping in view the importance of tar command, I’ll be writing full turorial on tar some day.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Date Command Tutorial(Video)
  • grep Command Tutorial – 1(Video)
  • Introduction To ls Command(Video)
  • Chapter 3
  • Set Position Of Poll Module Into Joomla

Recent Comments

  • Kansas City Trailer Proz on Physical Volume In AIX – A Primer
  • Create volume group in AIX | myunixsheet on How To Create Volume Group
  • Restore of AIX backup on other Unix system - TecHub on What is mksysb And What Are Its Components
  • Firewall Unleashed - InfoSec Institute on Packet Filtering Firewall: An Introduction
  • Manwendra on Proxy Firewall and Gateway Firewall: Introduction

Archives

  • January 2019
  • June 2010
  • May 2010
  • February 2010
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008

Categories

  • 30 Days To Joomla WebSite Setup
  • A Journey To The World of Linux System Administration
  • Aix
  • Backups
  • Books
  • Firewalls
  • Introduction
  • Joomla
  • Joomla Backup
  • Joomla Web Technology
  • Linux
  • LPAR and Virtualization
  • LVM
  • Pluggable Authentication Modules
  • section navigator pro
  • Security
  • Security Knowledge Base
  • Tips and Tricks
  • Uncategorized
  • World is Welcome Products

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
©2023 World is Welcome To The World of Linux | WordPress Theme by SuperbThemes