LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 02-02-2012, 01:40 PM   #1
julian16
LQ Newbie
 
Registered: Aug 2009
Posts: 20

Rep: Reputation: 0
tar: "preserve the symbolic links"


I have a need to migrate a web site tree and I wish to "preserve the symbolic links" with tar -- that is, to keep the symbolic link "as is" without copying the targeted files. The regular 'tar cf' copied target files for each symbolic link thus duplicated the files many times that I lost track which one should be the "original" file on the new site.

I used tar option 'h' as in 'tar chf' but that does the same as the default behavior. I failed to find which option does the opposite. Any advice please?

joe
 
Old 02-03-2012, 12:50 AM   #2
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 193Reputation: 193
Well for me this works..

Code:
~/tmp $ tar -cpvzf /tmp/tarball.tar.gz *
file1
file10
file2
file3
file4
file5
file6
file7
file8
file9
linkname
~/tmp $ tar -ztvf /tmp/tarball.tar.gz 
-rw-r----- fukawi1/fukawi1   0 2012-02-03 17:33 file1
-rw-r----- fukawi1/fukawi1   0 2012-02-03 17:33 file10
-rw-r----- fukawi1/fukawi1   0 2012-02-03 17:33 file2
-rw-r----- fukawi1/fukawi1   0 2012-02-03 17:33 file3
-rw-r----- fukawi1/fukawi1   0 2012-02-03 17:33 file4
-rw-r----- fukawi1/fukawi1   0 2012-02-03 17:33 file5
-rw-r----- fukawi1/fukawi1   0 2012-02-03 17:33 file6
-rw-r----- fukawi1/fukawi1   0 2012-02-03 17:33 file7
-rw-r----- fukawi1/fukawi1   0 2012-02-03 17:33 file8
-rw-r----- fukawi1/fukawi1   0 2012-02-03 17:33 file9
lrwxrwxrwx fukawi1/fukawi1   0 2012-02-03 17:32 linkname -> /tmp/link_dest/
That is the normal way i create a tar. I would imagine the -p option is preserving the permissions (the 'lrwrwxrwx') when it adds the link.
 
Old 02-03-2012, 01:11 AM   #3
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
The tar command should preserve symbolic links by default. I just tried a couple different attempts on my system using "tar cvjf tarball.tar.bz2 testdirectory/". I had links inside testdirectory that pointed to files within the directory and links that pointed outside the directory. All links were created--no dereferences.

Like I said, tar should preserve the symbolic links by default. So, you might want to check two things:

1. See if you have an alias for tar that includes the '-h' option automatically
2. Check your version of tar against any possible bug reports

For reference, my tar:
Code:
user@localhost$ tar --version
tar (GNU tar) 1.23
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by John Gilmore and Jay Fenlason.

Last edited by Dark_Helmet; 02-03-2012 at 01:12 AM.
 
Old 02-04-2012, 11:24 PM   #4
julian16
LQ Newbie
 
Registered: Aug 2009
Posts: 20

Original Poster
Rep: Reputation: 0
Thank you both for your input. Our older RH Linux server was upgraded hence I could not verify. What you describe is repeatable on our new linux box though. Many thanks for taking time. Appreciated!
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"creating symbolic link" "operation not permitted" wheni Linux - Newbie 3 05-08-2011 01:36 AM
"tar -xzf" error: "tar.child died with signal 13" vlsi Linux - General 4 05-26-2009 02:04 AM
"Too many levels of symbolic links" Problem Corallis Linux - Newbie 5 07-12-2004 01:18 PM
ProFTPD - "Too many levels of symbolic links" orange400 Linux - Software 5 04-29-2004 06:55 AM
Can't mount CDROM: "Too many levels of symbolic links" wycolorado Linux - Newbie 10 08-15-2003 10:56 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:45 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