LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 02-09-2002, 07:47 PM   #1
ryanstrayer
Member
 
Registered: Jan 2002
Location: Kansas City
Distribution: RedHat 7.2 Kernel 2.4.17
Posts: 250

Rep: Reputation: 30
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?
 
Old 02-09-2002, 07:56 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
for i in $1
do
if [ -L $i ]
then
cp $1 $2
fi
done
 
Old 02-09-2002, 08:22 PM   #3
ryanstrayer
Member
 
Registered: Jan 2002
Location: Kansas City
Distribution: RedHat 7.2 Kernel 2.4.17
Posts: 250

Original Poster
Rep: Reputation: 30
Uhmmm Ok - forgive my stupidity - but just what do I do with that?
 
Old 02-09-2002, 08:37 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
it's a script, put it in a file, make it executable and run it....

eg.

./copylinks * /tmp/links/
 
Old 02-09-2002, 09:26 PM   #5
ryanstrayer
Member
 
Registered: Jan 2002
Location: Kansas City
Distribution: RedHat 7.2 Kernel 2.4.17
Posts: 250

Original Poster
Rep: Reputation: 30
K - Did that... it ran.. copied nothing?
 
Old 02-09-2002, 09:31 PM   #6
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
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
 
Old 02-09-2002, 09:37 PM   #7
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
no it didn't did it

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

there, needs to be in the same directory tho.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
symbolic links durden2.0 Linux - Newbie 6 11-12-2008 03:06 AM
Symbolic Links Greg_courageous Linux - Newbie 1 05-10-2004 07:05 AM
Symbolic links? TongueTied Linux - Newbie 3 08-27-2003 06:00 AM
Symbolic Links petercool Linux - General 2 08-20-2003 11:15 AM
symbolic links NoahsMyBro Linux - Newbie 1 11-16-2001 11:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:38 PM.

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