LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 03-20-2019, 12:37 PM   #1
triplemaya
LQ Newbie
 
Registered: May 2006
Posts: 26

Rep: Reputation: 1
Transfer directory of links to new pc


I am trying to simply copy my Dropbox directory over to my new pc. Everything is the same, username, directory structure etc. The Dropbox directory is full of links. Nothing I try works. I have tried all the options on these pages:

https://stackoverflow.com/questions/...-symbolic-link

https://superuser.com/questions/1385...symbolic-links

running Ubuntu 18.045 MATE

I have already transferred all the files by sneaker net. That is all done. Now I am trying to set up dropbox.

On the 'parent' computer the dropbox directory contains all links. The links are to the various directories on my system I want synced. I need to set up the dropbox directory in the new computer with these links. Doing them one by one is feasible but time consuming. What I want to do is copy the existing 'parent' directory, with all the links, on the original computer, which is still in operation, to the new computer.

Last edited by triplemaya; 03-21-2019 at 08:36 AM. Reason: SOLVED
 
Old 03-20-2019, 03:58 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
If you have the original links you can generate a script to recreate them by running the follow

Code:
ls -l $(find . -type l) |awk '{print "ln -s "$11,$9"; chown -h "$3":"$4,$9} >mk_links.sh
The find within that looks for symbolic link files. That is encapsulated in $() so the ls -l at start will show you all the details of the files. The awk then parses the ls -l output so that uses field 11 (the target) and field 9 (the slink file) as input to "ln -s" to create the link. The chown -h is then used to set same owner and group (fields 3 and 4) on the slink file that the original slink had.

Example:
In /mylinks/subdirectory if I have an slink:
lrwxrwxrwx 1 billybob dba 55 Jul 13 2016 myslink -> /home/ralph/realfile

The above command run will output a line in my_links.sh:
ln -s /home/ralph/realfile myslink ; chown -h tstaappl:dba myslink

The original command line that created my_links.sh would have an entry for each slink found.

You can copy my_links.sh to the new server in the directory, make it executable and run it.

Note the above assumes that all the existing slinks found are more than a day old. You'd have to adjust it if they weren't because the time field would be used instead of the date fields and adjust the order of the remaining fields. It also assumes you've created the same user(s) and group(s) on the new server as you'd had on the original that were used for slink files.
 
1 members found this post helpful.
Old 03-21-2019, 04:22 AM   #3
agillator
Member
 
Registered: Aug 2016
Distribution: Mint 19.1
Posts: 419

Rep: Reputation: Disabled
CREATE A TEST DIRECTORY ON YOUR NEW MACHINE SO NOTHING GETS SCREWED UP.
Assuming you have ssh access to your new machine from your old machine, the name of your new machine is fred, your username on both machines is george and the directory path is /home/george/Dropbox on the old machine and /home/george/testdir on the new, and the target files actually exist on the new machine in the exact same filepath as on the old machine:
Code:
rsync -av /home/george/Dropbox/ george@fred:/home/george/testdir/
This should copy EVERYTHING from the old directory to the new including subdirectories. If there are things you want to exclude then look at the man page to see how to exclude them. Check the new directory carefully to make sure thigs were transferred as you want them to be. If so you can rename you directory to what it should be or run the command again with the real destination directory. If you run into problems with permissions then run as the appropriate user. Sudo will usually work and you can correct the destination permissions after a successful transfer. Note that sym links will be copied exactly which means the linked file must be on the exact same filepath as the old or the link will be broken.
 
Old 03-21-2019, 08:35 AM   #4
triplemaya
LQ Newbie
 
Registered: May 2006
Posts: 26

Original Poster
Rep: Reputation: 1
Many thanks for your replies. The links was the issue. This is what works on links to directories:
cp -rP

When trying to get this to work I missed the comment in the quoted articles:
You might need to add -R, because otherwise cp will skip directories and symlinks to directories.
So I kept getting the message that the link I wanted to copy was skipped.
 
1 members found this post helpful.
  


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
[SOLVED] how to list files in directory or generate links for files in a directory darksaurian Programming 7 08-08-2015 01:28 PM
web page/links links/links vendtagain Linux - Newbie 2 09-19-2009 08:13 PM
links (hard links and soft links..) sachitha Programming 1 08-10-2005 12:10 PM
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 - Distributions > Ubuntu

All times are GMT -5. The time now is 12:26 AM.

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