Delete and Recreate around 400 Symbolic Links in one Folder


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete and Recreate around 400 Symbolic Links in one Folder
# 1  
Old 04-23-2011
Delete and Recreate around 400 Symbolic Links in one Folder

Hello,

I recently just switched my phphandler to suPHP on my server in order to increase security a bit. I am working with 2 scripts, one of which is vbulletin forums and the other is custom. The vbulletin forum avatars are all symbolic links to pictures in the other custom script. When I switched to suPHP, all of the avatars stopped showing up in my forum. So I went to changed all the permissions on the image files in the actual image folder. That didn't work completely so I went into the symbolic link folder and deleted and recreated a few links. It seems that only recreating them makes them take the new permissions. Each one of the recreated ones works. So now I am faced with having to delete and recreate about 400 links. Is there any way to script this to help out? Or is there another way to update the links without removing and remaking them? Thanks in advance for any help.
# 2  
Old 04-24-2011
try this from within your folder with the links:
Code:
find . -type l | xargs ls -l | awk '{system("ln -sf " $11" "$9)}'

Although, you may want to test this first or it will mess up your links:
Code:
find . -type l | xargs ls -l | awk '{print "ln -sf " $11" "$9}'

then if it looks ok:
Code:
find . -type l | xargs ls -l | awk '{print "ln -sf " $11" "$9}'  | sh

This User Gave Thanks to kato For This Post:
# 3  
Old 04-24-2011
It worked! Wow man you just saved me so much data entry it's not funny. I appreciate this SO much. Smilie


Quote:
Originally Posted by kato
try this from within your folder with the links:
Code:
find . -type l | xargs ls -l | awk '{system("ln -sf " $11" "$9)}'

Although, you may want to test this first or it will mess up your links:
Code:
find . -type l | xargs ls -l | awk '{print "ln -sf " $11" "$9}'

then if it looks ok:
Code:
find . -type l | xargs ls -l | awk '{print "ln -sf " $11" "$9}'  | sh

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Recreate/Restore Repository and/or change/delete Public Keys???

I have a BIG problem... I host a public (Debian) repository on Cydia (for jailbroken iphones). I use my home Mac running Ubuntu in VMWare Fusion. For the repository, I have to have 5 items in a folder to make it 'live:' 1. deb_files folder (to hold my Debian packages) 2. Packages file 3.... (0 Replies)
Discussion started by: thazsar
0 Replies

2. Solaris

Symbolic links

Soft link,Hard link brief explanation (1 Reply)
Discussion started by: RAJU KAVATI
1 Replies

3. Ubuntu

How to find symbolic links recursively under a folder in Linux

Hi , I have folder which has almost 35000 objects, I need to find out or list the objects which are symbolic links. I tried f. I am not getting right Can you pls help Regards amv (5 Replies)
Discussion started by: amvarma77
5 Replies

4. UNIX for Dummies Questions & Answers

Symbolic Links

Hi all, I have scoured the entire forum for this but to no avail unfortunately. Basically, I would like to remove my symbolic link from my folder name i.e. foldername -> /a/b/c/d/f where f is indeed a folder. I have tried rmdir but this does not work and in actual fact deletes the... (4 Replies)
Discussion started by: cyberfrog
4 Replies

5. Solaris

symbolic links between servers

Hi Guys... I want to create a link using ln -s for a directory that does not exist on the box. How do I do that? I had some files from Box A directory /d1/u01 and I copied the files across to another Box lets say Box B on directory /d2/u02. Now I want a link so that this path /d1/u01... (2 Replies)
Discussion started by: Phuti
2 Replies

6. Solaris

how to recreate scripts under /etc/rc3.d folder

Hi All, We have the JMS Queue startup script S52imq and some other scripts in our solaris server 5.8 version. now unknowingly something happend to those scripts and its lost. How can I recreate those scripts again to start the JMQ queue again? We have Solaris 5.10 version which is having... (3 Replies)
Discussion started by: nsurendiran
3 Replies

7. AIX

Symbolic Links

I am linking a directory as follows: ln -sf /home/xxx/userid/real_files/* /home/xxx/userid/linked_files This gives me symbolic links for all the files in the real_files directory in the linked_files directory. My question is, if I go and remove a file in the real_files directory and then go... (1 Reply)
Discussion started by: rcarnesiii
1 Replies

8. Solaris

cp a dty without symbolic links?

Hi, - we have copy (cp command) to do to save all the contents of a dty BUT we dont want to copy the files corresponding to symbolic links contained whithin this dty - the box is a sun solaris one - and the cp commande do not say avything about that? thanks for help Jakez (7 Replies)
Discussion started by: JAKEZ
7 Replies

9. UNIX for Dummies Questions & Answers

Too many levels of symbolic links

Hi, Is there a limit to the number of symbolic links you can have? I tried to vi the symbolic link relating to a file and got the following error: "filename" Too many levels of symbolic links There is only one symbolic link to one file in this case, but there are >2000 other links to... (2 Replies)
Discussion started by: Bab00shka
2 Replies

10. UNIX for Dummies Questions & Answers

Finding symbolic links

How can I find all symbolic links across the network to a directory (2 Replies)
Discussion started by: mehtad
2 Replies
Login or Register to Ask a Question