Monday, November 12, 2007

Tar/Untar Simultaneously.

Here is a Nice Way to put all your data from one location to another in a fast way.
Traditionally a user woudl first tar his whole directory go to destination and the untar.
This takes more time and needs huge space.

Use the following command instead:

tar cf - "data to be tarred"|(cd destination; tar xf -)

There is a very simple concept behind this command:
The hyphon ( "-") in the command is stdout.
So basically the file in which we are tarring the data is streaming the tarred data to stdout (not saving it).
The '|' lets us parse the stream and tar xf - untars the stream at the place defined by cd destination command.

For doing it from a different machine just add rsh machine name in front of the command.

There are a few things which need to be kept in mind while doing these:

1. Never use v option of tar in this command.
Why: A very simple reason v throws the output of whatever is happening on STDOUT. the extraction part thinks that it is not a proper archive since it doesnt has the proper header and hence the command fails.

2. While using rsh remember that no extra rc(profile startup) files are there in the profile which give any output. the reason is the same.
Also remember that the rsh should be passwordless.

No comments: