Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 02-02-2012, 02:40 PM   #1
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?

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

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

~/tmp $ tar -cpvzf /tmp/tarball.tar.gz *
~/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, 02:11 AM   #3
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:
user@localhost$ tar --version
tar (GNU tar) 1.23
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <>.
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 02:12 AM.
Old 02-05-2012, 12:24 AM   #4
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!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 02:36 AM
"tar -xzf" error: "tar.child died with signal 13" vlsi Linux - General 4 05-26-2009 03:04 AM
"Too many levels of symbolic links" Problem Corallis Linux - Newbie 5 07-12-2004 02:18 PM
ProFTPD - "Too many levels of symbolic links" orange400 Linux - Software 5 04-29-2004 07:55 AM
Can't mount CDROM: "Too many levels of symbolic links" wycolorado Linux - Newbie 10 08-15-2003 11:56 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:34 PM.

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