LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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
 
LinkBack Search this Thread
Old 03-27-2011, 08:58 AM   #1
Siljrath
Member
 
Registered: Nov 2004
Location: the internet
Distribution: sid, slack, gentoo, witch, bedrock, etc
Posts: 145

Rep: Reputation: 25
copy only symbolic links between homes


copy all symlinks

i want to copy all symlinks (both active and dead) from one partition's os's user's home directory, to another partition's os's user's home directory, and i'm wondering if this can be accomplished with some clever bash options and pipes after "cp".

this is very useful for users with multiboot systems, who keep all their data on a separate drive. this would allow the symlink'ed shortcut tree directory hierarchy expedience, to be instantly copyable to any of their oses.

distro-hoppers/surfers will love it. ^_^

so here goes my first attempt at trying to work out what it'd be...

cp -P
(copy, dont follow symbolic links)
(or is it -d i aught use?)

find /% -type l
(finds symbolic links only
(replace /% with location to search in)

~/
(home directory of active system)

ok, sure, i know all that now, but how to link them so that the find comand's output is the input for the cp command....

|
(pipe)

... but the order...

ooh, maybe i use that first variable thingy... $1 right? ... like this...?

find /media/archboom/home/digit/ -type l | cp -P $1 ~/

it'll make a little test before trying it for real....

$ find /home/digit/foo/ -type l | cp -P $1 ~/fi/
cp: missing destination file operand after `/home/digit/fi/'
Try `cp --help' for more information.

er... nope.. didnt work.
cp --help isnt really the help i need here...
to linux questions i go! ^_^
 
Old 03-27-2011, 09:15 AM   #2
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
I would investigate the use of find with the exec option after the selection options.
Code:
find /home/user -t l -exec cp {} /mnt/otherplace/user \;
That code won't really work because it will follow the entire tree of the source directory but it will put all of the links into the same destination folder.

If only we could use tar. I don't think we can but tar can copy directory trees to a new tree.

I think the challenge here comes from trying to select individual files to go to an appropriate location in a destination directory tree. I don't see how to get around that in a one line command.

I can see how to make a script to do this. You could have a loop that would save the source directory tree name and use that to copy individual links to the destination. If the destination subdirectory doesn't exist then create it before the copy.

One more thought. Maybe rsync can do this. I am not familiar with all of the options of rsync since I don't use it at all.

Last edited by stress_junkie; 03-27-2011 at 09:39 AM.
 
Old 03-27-2011, 10:04 AM   #3
Siljrath
Member
 
Registered: Nov 2004
Location: the internet
Distribution: sid, slack, gentoo, witch, bedrock, etc
Posts: 145

Original Poster
Rep: Reputation: 25
i tried [tested]
Code:
 cp -P $(find /home/digit/foo/ -type l) ~/fi/
and it almost worked. ^_^
[edit- it added a broken symlink. a relative/absolute issue perhaps? so needs another option as well as / instead of "-P"...? maybe -d, maybe -Lsd... no joke.]



woah stress junkie, i think you're thinking i'm thinking of something else... that all sounds way too much... i'm just talking about copying symlinks. ^_^

Last edited by Siljrath; 03-27-2011 at 10:22 AM. Reason: edited the edit a couple times.
 
Old 03-27-2011, 10:06 AM   #4
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
I'm thinking that you have a directory tree with symlinks scattered throughout the structure and you want to copy them to corresponding locations in a similar directory tree.
 
Old 03-27-2011, 10:12 AM   #5
Siljrath
Member
 
Registered: Nov 2004
Location: the internet
Distribution: sid, slack, gentoo, witch, bedrock, etc
Posts: 145

Original Poster
Rep: Reputation: 25
actually, it's just in one directory, one layer...

that keeps it simpler, right? no recursion in-out nightmare.

just in ~/ only, and no directories further in the tree.

Last edited by Siljrath; 03-27-2011 at 10:16 AM. Reason: added elaboration for some redundant clarity.
 
Old 03-27-2011, 10:19 AM   #6
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Then I think that the find command that I provided in my first post should work. Maybe add a -maxdepth to keep the search in the one desired source directory.
 
  


Reply

Tags
bash, cp, migration, shortcuts, symlinks


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 On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Symbolic links Vs Hard links sulekha Linux - General 2 10-02-2008 07:03 AM
make a copy of a directorystructure and his files as symbolic links Byenary Linux - General 4 04-25-2008 08:18 PM
Copy Symbolic links from linux to windows Mini Singh Linux - General 2 08-30-2007 12:55 AM
KDE - symbolic links copy Artik Linux - Software 1 07-19-2005 05:14 PM
Symbolic Links petercool Linux - General 2 08-20-2003 11:15 AM


All times are GMT -5. The time now is 05:48 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration