JAUHARI.net has been move from one server to another server more than five times. And tar command is my favorite ways to move our website data from one server to another server. Okay.. here is the ways how to using tar to Archive Data and Folder
The program tar (originally for tape archive) is useful for archiving and transmitting files that available on Unix Family Operating System. Almost every Linux Installed Server already have tar program.
If you want to move your server data using tar command you need telnet/ssh enabled. If you hosting provider SSH didn’t activated you can request to enable it.I will explain a little bit more about many useful tar command. This information taken from Owen L. Astrachan on this page
Create, Extract, See Contents
The tar program takes one of three function command line arguments (there are two others I won’t talk about).
- c — to create a tar file, writing the file starts at the beginning.
- t — table of contents, see the names of all files or those specified in other command line arguments.
- x — extract (restore) the contents of the tar file.
(the other options are u for update and r for replace, see the man page for details).
Exactly one function argument, c, t, x, is used in conjunction with other command line arguments shown below. Again, these examples are not meant to be complete, just useful.
Compression, Verbose, File specified
In addition to a function command line argument the arguments below are useful. I usually use z and f all the time, and v when creating/extracting.
- f — specifies the filename (which follows the f) used to tar into or to tar out from; see the examples below.
- z — use zip/gzip to compress the tar file or to read from a compressed tar file.
- v — verbose output, show, e.g., during create or extract, the files being stored into or restored from the tar file.
Examples Tar Command
To tar all .cc and .h files into a tar file named foo.tgz use:
tar cvzf foo.tgz *.cc *.h
This creates (c) a compressed (z) tar file named foo.tgz (f) and shows the files being stored into the tar file (v). The .tgz suffix is a convention for gzipped tar files, it’s useful to use the convention since you’ll know to use z to restore/extract.
It’s often more useful to tar a directory (which tars all files and subdirectories recursively unless you specify otherwise). The nice part about tarring a directory is that it is untarred as a directory rather than as individual files.
[sourcecode language=”c”]tar cvzf foo.tgz cps100[/sourcecode]
will tar the directory cps100 (and its files/subdirectories) into a tar file named foo.tgz.
To see a tar file’s table of contents use:
[sourcecode language=”c”]tar tzf foo.tgz[/sourcecode]
To extract the contents of a tar file use:
[sourcecode language=”c”]tar xvzf foo.tgz[/sourcecode]
This untars/extracts (x) into the directory from which the command is invoked, and prints the files being extracted (v).
If you want to untar into a specified directory, change into that directory and then use tar. For example, to untar into a directory named newdir:
[sourcecode language=”c”]mkdir newdir
tar xvzf ../foo.tgz[/sourcecode]
You can extract only one (or several) files if you know the name of the file. For example, to extract the file named anagram.cc from the tarfile foo.tgz:
[sourcecode language=”c”]tar xvzf foo.tgz anagram.cc[/sourcecode]
That’s it, now you can trying in your hosting provider with SSH/Telnet. We hope this tutorial about using tar program with many example command will be useful. We will show you how to move website data to another server easily using Tar Command on the next post.