Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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! ^_^
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.