Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
08-09-2012, 07:12 AM
|
#1
|
Member
Registered: Oct 2010
Posts: 101
Rep:
|
tar absolute and relative path
hi guys
i have a problem with tar command
i use absolute path to make a backup
tar cvf backup /home/user
and when i try to restore backup it doesn't destroy my files
tar xvf backup
it makes a directory with the name of home in my current directory although i've heard if we use absolute path to make a backup when we want to restore files they will extract in the same absolute path
for example:
if i make a backup with absolute path with this command
tar cvf backup /home/user
i think when i want to restore the backup
backup will restore exactly in /home/user and destroy all user files
however when i tested that it only makes a directory with the name of home in my current directory !!
is that right ??
another example :
according to this example
for backing up, you use
[/backups]# tar -cvf backup /home/user
& then you restore using
[/backups]# tar -xvf backup
the files will be restored to /home & not /backups,
but my files restored exactly in /backup a new directory with the name of home
Last edited by mmhs; 08-09-2012 at 07:18 AM.
|
|
|
08-09-2012, 07:36 AM
|
#2
|
Senior Member
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238
Rep: 
|
Quote:
Originally Posted by mmhs
i think when i want to restore the backup
backup will restore exactly in /home/user and destroy all user files
however when i tested that it only makes a directory with the name of home in my current directory !!
is that right ??
|
Yes. But here's how you specify output dir.
|
|
|
08-09-2012, 08:13 AM
|
#3
|
Member
Registered: Oct 2010
Posts: 101
Original Poster
Rep:
|
Quote:
Originally Posted by Mr. Alex
|
bu it did not happen when i restore a tar file which was made with absolute path it didn't destroy my files !
|
|
|
08-09-2012, 08:19 AM
|
#4
|
Member
Registered: Aug 2006
Posts: 609
Rep:
|
Quote:
Originally Posted by mmhs
bu it did not happen when i restore a tar file which was made with absolute path it didn't destroy my files !
|
You probably need -C / when extracting.
That will extract any dirs/subdirs/content directly under /.
tar tvf filename.tar.gz
This should show entries like
your/path/backed/up
Without slash at the start of the line.
|
|
|
08-09-2012, 08:38 AM
|
#5
|
Member
Registered: Oct 2010
Posts: 101
Original Poster
Rep:
|
Quote:
Originally Posted by deadeyes
You probably need -C / when extracting.
That will extract any dirs/subdirs/content directly under /.
tar tvf filename.tar.gz
This should show entries like
your/path/backed/up
Without slash at the start of the line.
|
did you read my question ???
i want to know the meaning of absolute path in tar !!!
it was written in a book when i use absolute path to make a backup when i want to restore the backup all file will restore in the same absolute path
e.g
for backing up, i use
[/backups]# tar -cvf backup /home/user
& then i restore using
[/backups]# tar -xvf backup
the files will be restored to /home & not /backups,
bu it did not happen for me ! my question is why ???
when i restored backup with above command all files restored in /backup instead of /home/user !!!! why ??
Last edited by mmhs; 08-09-2012 at 08:45 AM.
|
|
|
08-09-2012, 09:01 AM
|
#6
|
Senior Member
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238
Rep: 
|
Quote:
Originally Posted by mmhs
bu it did not happen for me ! my question is why ???
when i restored backup with above command all files restored in /backup instead of /home/user !!!! why ??
|
Because GNUtar acts this way I guess... Extraction goes to current directory by default.
|
|
|
08-09-2012, 09:05 AM
|
#7
|
Senior Member
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238
Rep: 
|
http://lowfatlinux.com/linux-tar.html
Quote:
tar xvf panda.tar Extract files from panda.tar.
This will copy all the files from the panda.tar file into the current directory. When a tar file is created, it can bundle up all the files in a directory, as well as any subdirectories and the files in them. So when you're extracting a tar file, keep in mind that you might end up with some new subdirectories in the current directory.
|
|
|
|
08-09-2012, 09:10 AM
|
#8
|
Member
Registered: Aug 2006
Posts: 609
Rep:
|
Quote:
Originally Posted by mmhs
did you read my question ???
i want to know the meaning of absolute path in tar !!!
it was written in a book when i use absolute path to make a backup when i want to restore the backup all file will restore in the same absolute path
e.g
for backing up, i use
[/backups]# tar -cvf backup /home/user
& then i restore using
[/backups]# tar -xvf backup
the files will be restored to /home & not /backups,
bu it did not happen for me ! my question is why ???
when i restored backup with above command all files restored in /backup instead of /home/user !!!! why ??
|
tar tvf filename.tar.gz will show you what path components are in the path.
-C specifies the directory to start with. So each entry in the tar tvf ... listing will be added to the path specified with -C.
Copy from man page(this way you can remove part of the path taking into the tar tvf output):
Code:
--strip-components NUMBER, --strip-path NUMBER
strip NUMBER of leading components from file names before
extraction
(1) tar-1.14 uses --strip-path, tar-1.14.90+ uses --strip-compo-
nents
Please post tar tvf output (only a few lines is ok).
|
|
|
08-09-2012, 09:21 AM
|
#9
|
Senior Member
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238
Rep: 
|
Quote:
Originally Posted by deadeyes
Please post tar tvf output (only a few lines is ok).
|
It's just that his source absolute path becomes relative in tar archive (for extraction), that's pretty much covers it.
|
|
|
08-09-2012, 09:50 AM
|
#10
|
Member
Registered: Oct 2010
Posts: 101
Original Poster
Rep:
|
Quote:
Originally Posted by Mr. Alex
|
http://docstore.mik.ua/orelly/unix/upt/ch20_10.htm
see here
One problem with most versions of tar : it can't change a file's pathname when restoring. Let's say that you put your home directory in an archive (tape or otherwise) with a command like this:
%
tar c /home/mike
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/mike already exists, it will be destroyed
Tarfiles should not normally be created with absolute pathnames, only
with relative pathnames. Do not type "tar c /path/name" to create a tar
archive, type "(cd /path/name; tar c .)" instead.
Last edited by mmhs; 08-09-2012 at 10:02 AM.
|
|
|
08-09-2012, 10:08 AM
|
#11
|
Senior Member
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238
Rep: 
|
The book's name is "UNIX power tools". As you probably know, there are several versions of TAR. UNIX and GNU is not the same.
Plus,
By Jerry Peek, Tim O'Reilly & Mike Loukides; ISBN 1-56592-260-3, 1120 pages.
Second Edition Edition, August 1997.
Plus,
your URL also says:
Use GNU tar (on the CD-ROM). It can ignore the leading / as it extracts files.
You use GNU tar, don't you? If "/" in the beginning is removed, path becomes relative. It is then extracted into current dir by default and path in tar archive concatenates with current dir's path. Deal with it.
Last edited by Mr. Alex; 08-09-2012 at 10:11 AM.
|
|
1 members found this post helpful.
|
08-09-2012, 10:13 AM
|
#12
|
Senior Member
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238
Rep: 
|
Quote:
Originally Posted by deadeyes
You probably need -C / when extracting.
That will extract any dirs/subdirs/content directly under /.
tar tvf filename.tar.gz
|
You don't need "v" option here. Just "tf".
|
|
|
08-09-2012, 12:20 PM
|
#13
|
Senior Member
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,811
|
In the manpage for tar, see the "-P" (--absolute-names) option. You would need to have used that when creating the archive.
|
|
|
08-09-2012, 08:09 PM
|
#14
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,429
|
As above:
by default, gnu tar drops the leading '/' when creating an archive.
You can use tar tf ... to see this.
You then have the option of (default) restore into current dir, OR use a switch to specify where to anchor the restore.
Your choice. 
|
|
1 members found this post helpful.
|
All times are GMT -5. The time now is 01:38 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|