In Unix and GNU/Linux systems, the name of the tar command is short for tape archiving, the storing of entire file systems onto magnetic tape, which is one use for the command. However, a more common use for tar is to simply combine a few files into a single file, for easy storage and distribution.
Sometimes you can get the following error message when use tar command:
tar: Removing leading `/' from member names
One problem with most versions of tar command is that it's not able to change a file's pathname when restoring.
For example, if we put our home directory in an archive using the following command:
% tar c /home/user
What will these files be named when you restore them, either on your own system or on some other system? They will have exactly the same pathnames that they had originally. So if /home/user already exists, it will be destroyed. There's no way to tell tar that it should be careful about overwriting files; there's no way to tell tar to put the files in some other directory when it takes them off the tape, etc. If you use absolute pathnames when you create a tape, you're stuck. If you use relative paths (e.g., tar c .), you can restore the files in any directory you want. Consider that GNU tar converts absolute pathnames to relative, by default. Most other tars don't do that, so I don't advise relying on the feature.
This means that you should:
Avoid using absolute paths when you create an archive
Use tar t to see what files are on the tape before restoring the archive
Use GNU tar (on the CD-ROM). It can ignore the leading / as it extracts files
Instead giving a command like tar c /home/user, do something like:
% cd /home/user% tar c .
Or, even more elegant, use -C on the tar command line:
% tar c -C /home/user .
This command tells tar to cd to the directory /home/user before creating the archive. If you want to archive several directories, you can use several -C options:
% tar c -C /home/user1 ./docs -C /home/user2 ./media
This command archives user1's docs directory and user2's media directory.
As an example you can check out our article how to backup website with shell script using tar and gzip commands.