LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Copying Symbolic Links (https://www.linuxquestions.org/questions/linux-general-1/copying-symbolic-links-13930/)

ryanstrayer 02-09-2002 07:47 PM

Copying Symbolic Links
 
Okay - well I guess I'm an idiot.. I can't find how to do this .. I have a directory with quite a few symbolic links in it, and I need to copy all the links themselves to a backup directory (not the file the links are pointing to) .. is there a way I can do a mass copy of just the links to somewhere? I've found the switch to to not follow the links, but how do I tell it to just copy symbolic links... in other words, distinguish those files from all the others?

acid_kewpie 02-09-2002 07:56 PM

for i in $1
do
if [ -L $i ]
then
cp $1 $2
fi
done

ryanstrayer 02-09-2002 08:22 PM

Uhmmm Ok - forgive my stupidity - but just what do I do with that?

acid_kewpie 02-09-2002 08:37 PM

it's a script, put it in a file, make it executable and run it....

eg.

./copylinks * /tmp/links/

ryanstrayer 02-09-2002 09:26 PM

K - Did that... it ran.. copied nothing?

crabboy 02-09-2002 09:31 PM

This will search for all the symlinks in a directory tree starting at the directory you are in and copy them as symlinks to a directory called /tmp/new.
Code:

find . -type l -exec cp -d {} /tmp/new \;
You can change your starting directory by either chaning to that directory or replacing the '.' with the directory name. Change the destination directory by replacing the /tmp/new.

If you want to keep the directory tree structure in tact then you could issue this command:
Code:

find . -type . | cpio -pvmd /tmp/new

acid_kewpie 02-09-2002 09:37 PM

no it didn't did it :D

for i in *
do
echo $i
if [ -L "$i" ]
then
cp "$i" "$1"
fi
done

there, needs to be in the same directory tho.


All times are GMT -5. The time now is 11:32 AM.