tar symlinks: relative vs absolute

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers tar symlinks: relative vs absolute
# 1  
Old 08-20-2009
tar symlinks: relative vs absolute

I create the tar file from / like so:

tar cEhf name.tar usr/us

And this creates the tar with the links intact. The problem is that this tar is going to be used for testing, so we want the links to point to the files in the tar. But when I extract the tar into /tmp, I get /tmp/usr/us/... as I expect, but the links are NOT /tmp/usr/us/... like I want but are /usr/us/...; the original location.

Is there a way to get the links to be relative the same way the rest of the files are?

System is Solaris 10 and I have been using tar xvf to extract. I'm hoping the problem is in the extraction since it will take several hours to rebuild a pristine system to redo the tar files if that's where the change needs to be made.Smilie

Oh, and finally, the links are important to what we are testing, so replacing the link with just a copy of what the link points to will not satisfy the conditions of the test.

# 2  
Old 08-21-2009
Clearly you understand why you should not use absolute path while creating tar file. Same rule applies for links. If you use absolute path for link, it will remain so. Solution is to create links with relative path.
eg: cd /usr
ln -s us us1
# 3  
Old 08-21-2009
Thanks for the reply. I tried to do this with mixed results. If the link was farther down the path, it woked, ie:

ln -s test/test/filea.txt filea.txt

This is restored no problem. But if I have a link like so:

ln -s ../test/filea.txt filea.txt

Then even though the parent dir and it's child 'test' are in the tar, the link is replaced with an actual copy of the file, so that an ls -al will show a file there now instead of a link. This does make sense to my why it would work this way, but I need it to not work that way. Smilie

Maybe tar is the wrong answer. I really just need to be able to archive up a bunch of files under /usr and then extract them under /tmp/test and have any links in there that used to point to /usr/... now point to /tmp/test/... Is this possible? The alternative will be to make a list of the symlinks using something like 'find . -type l' and then create a script to insert the symlinks after extraction. This is a less desirable option.

Thanks again

Edit: the less desirable option won. I made a script to go in and redo the absolute links so they use the new absolute path.

Last edited by TreeMan; 08-21-2009 at 06:58 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Convert Relative path to Absolute path, without changing directory to the file location.

Hello, I am creating a file with all the source folders included in my git branch, when i grep for the used source, i found source included as relative path instead of absolute path, how can convert relative path to absolute path without changing directory to that folder and using readlink -f ? ... (4 Replies)
Discussion started by: Sekhar419
4 Replies

2. Shell Programming and Scripting

Show only the filenames under a directory without relative and absolute paths.

I am able to list all the filenames under a directory & its sub-directories except blent.tar on Linux find "/tmp/" -type f | grep -v blent.tar | rev | cut -d '/' -f1 | rev Desired Output: THIRDPARTYLICENSEREADME.txt javaws libjavaplugin_oji.so libjavaplugin_oji.so... (3 Replies)
Discussion started by: mohtashims
3 Replies

3. UNIX for Dummies Questions & Answers

How to convert relative path to absolute path?

Hello Everyone, I want to convert Relative Path - /home/stevin/data/APP_SERVICE/../datafile.txt to Absolute Path - /home/stevin/data/datafile.txt Is there a built-in tool in Unix to do this or any good ideas as to how can I implement this. -Steve (5 Replies)
Discussion started by: qwarentine
5 Replies

4. Shell Programming and Scripting

tar and relative paths

HOw can I create a tar file with relative paths find . -depth -print | xargs tar -cvf /tmp/file.tar ? Thanks to all who answer (1 Reply)
Discussion started by: BeefStu
1 Replies

5. UNIX for Advanced & Expert Users

accessing NFS absolute path symlinks from windows/cygwin

Hi experts, I was wondering if there is a way to access some NFS symlink files that are set using absolute paths from Windows? On windows/cygwin, I'm able to access relative path symlinks but not the absolute path symlinks. Assume on Linux (mylinux): /usr/local/file.c ln -s... (1 Reply)
Discussion started by: andredz
1 Replies

6. Shell Programming and Scripting

absolute path for a script ran with relative path

I have a script in which i want to print absolute path of the same script irrespective of path from where i run script. I am using test.sh: echo "pwd : `pwd`" echo "script name: $0" echo "dirname: `dirname $0`" when i run script from /my/test/dir/struct as ../test.sh the output i... (10 Replies)
Discussion started by: rss67
10 Replies

7. UNIX for Dummies Questions & Answers

Absolute and Relative Paths?

Can someone cofirm that I have got the paths correct here? :confused: $PATH_TO_TMP_DIR='/tmp'; #$PATH_TO_TMP_DIR='home/tmp'; $PATH_TO_YOUR_IMG_DIR = '/temp_images'; #$PATH_TO_YOUR_IMG_DIR = 'home/public_html/Midwich/temp_images'; Thanks (1 Reply)
Discussion started by: stubie
1 Replies

8. Solaris

Extracting file from tar at relative location!!

Hi Gurus, I have a .tar file which required untar to the new location. I list the content with –tvf its listing the files which are inside the tar, when I am extracting he file from tar its working fine, however once I am trying to extract the file at the new location I am unable to do so. I... (11 Replies)
Discussion started by: kumarmani
11 Replies

9. UNIX for Dummies Questions & Answers

vi - replacing a relative path with absolute path in a file

Hi, I have a file with about 60 lines of path: app-defaults/boxXYZ....... I want to change this to /my/path/goes/here/app-defaults/boxXYZ, but of course vi doesn't like the regualr :s/old/new/ command. Is there any other quick way to do this? Thanks ;) (2 Replies)
Discussion started by: Yinzer955i
2 Replies

10. Shell Programming and Scripting

Relative directory - NOT absolute

Here is the drill, I am using a script to login to a remote ftp, and put and get files. My question is: I want to login and automatically change to the same directory I am in on my machine. I can not use $home, pwd or anyother env variable (that I know) since the names of the machines are totally... (4 Replies)
Discussion started by: sierra_aar
4 Replies
Login or Register to Ask a Question