LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-28-2007, 04:36 AM   #1
xeon123
Member
 
Registered: Sep 2006
Posts: 374

Rep: Reputation: 16
Tarball with links


1 - Suppose that i've a directory that has several symbolic links that points to different places of the filesystem. If i want to do a tarball to the respective directory, how do i set the option to also include in the tarball the filesystem structure where the links points to?

2 - The same question, but, for hard link?

Thanks,
Pedro
 
Old 02-28-2007, 07:10 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
In the GNU version of tar it is done by default (no options needed). The soft links are preserved, even if the file they link to has been removed (in this case you get a broken link). On the other hand, there is an option to dereference links:
Quote:
-h, --dereference
don’t dump symlinks; dump the files they point to
The hard links are copied as is.

This all is not true for the UNIX version of tar!

Last edited by colucix; 02-28-2007 at 07:15 AM.
 
Old 02-28-2007, 07:20 AM   #3
xeon123
Member
 
Registered: Sep 2006
Posts: 374

Original Poster
Rep: Reputation: 16
I think, i don't understand your answer.

If i've the a link, let's call "ln_test" in /home/user/ directory, that points to /opt/test.txt. If i do, tar -cvf zipped.tar ln_test, i want that /opt/test.txt also be included in the tarball, together with the link.

Is this possible.
 
Old 02-28-2007, 07:21 AM   #4
xeon123
Member
 
Registered: Sep 2006
Posts: 374

Original Poster
Rep: Reputation: 16
I forgot to put the question:

Is this possible?
 
Old 02-28-2007, 07:32 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by pedrosacosta
If i do, tar -cvf zipped.tar ln_test, i want that /opt/test.txt also be included in the tarball, together with the link
I think I did not understood the problem! I am afraid it is not possible. Indeed, to spread some files all over the system is a task for a kind of installer.
 
Old 02-28-2007, 07:41 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Sorry, my previous post was not really true, in the sense you can do something like
Code:
tar cvf file.tar dir_one dir_two
to archive multiple directory in one tarball. Anyway, I think there is no option to automatically follow links to include the files they point to (with their absolute path, I mean). Furthermore you will face another problem: in absolute paths (those beginning with /) the leading / is stripped out to minimize the risk of overwriting system files!

Last edited by colucix; 02-28-2007 at 07:46 AM.
 
Old 02-28-2007, 08:34 AM   #7
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Rep: Reputation: 87
Dereferencing the links makes the pointed to location copied to the tar file as well. Thats what I got from the statement above.

Quote:
In the GNU version of tar it is done by default (no options needed). The soft links are preserved, even if the file they link to has been removed (in this case you get a broken link). On the other hand, there is an option to dereference links:
Quote:
-h, --dereference
don’t dump symlinks; dump the files they point to
The hard links are copied as is.
This all is not true for the UNIX version of tar!
 
Old 02-28-2007, 09:01 AM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Yes, but not in the way the OP expected! Option -h copies the file in place of the link, assigning the name of the link itself to the copied file. For example, if I have the following link
Code:
my_link -> /usr/local/testfile.txt
The file testfile.txt will be copied into the archive in place of the symbolic link and will be named my_link (the path and name of the file the link pointed to, will be lost).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
technical question about hard links v soft links 7stud Linux - Newbie 2 02-23-2007 06:57 PM
links (hard links and soft links..) sachitha Programming 1 08-10-2005 12:10 PM
Sym links and hard links akudewan Linux - Newbie 4 02-09-2005 05:08 AM
how to change relitive links to specific links? wolfe2554 Linux - General 4 07-03-2004 12:40 AM
Links Section updated - Please add your Linux links. jeremy Linux - General 2 11-24-2001 11:35 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration