1833030 Members
2286 Online
110049 Solutions
New Discussion

Checking for Links

 
SOLVED
Go to solution
George Abraham_3
Occasional Advisor

Checking for Links

Hello Gurus,

I need a script that can check a specific directory(/home/george) and grab all the files with Symbolic links. Then it must remove the links and mail me the details.

Thanks in advance.

6 REPLIES 6
Mel Burslan
Honored Contributor

Re: Checking for Links

would this following code snippet be useful ?

find /home/george -type l > /tmp/links.george
for link in `cat /tmp/george`
do
echo "link $link removed" >> /tmp/mailfile
rm $link
done
sendmail george@domain.com < /tmp/mailfile
rm /tmp/links.george /tmp/mailfile

________________________________
UNIX because I majored in cryptology...
George Abraham_3
Occasional Advisor

Re: Checking for Links

hey Mel

Thanks for the reply but i dont want to remove the file.. Just remove the Link...

rm $link as you say will delete the file?

regards
George
Eric SAUBIGNAC
Honored Contributor

Re: Checking for Links

Hi Georges,

try this :

find /home/georges -type l | xargs rm -f

Eric
George Abraham_3
Occasional Advisor

Re: Checking for Links

Hey i just want to remove the symbolic link and NOT THE FILE

regards
george
Patrick Wallek
Honored Contributor
Solution

Re: Checking for Links

If you have something like:

lrw-rw-rw- 1 user user 96 Oct 04 11:35 file1 -> file

Now file1 is the link and file is the real file.

If you do:

# rm file1

That will just remove the file1 link. It will NOT remove file.
Eric SAUBIGNAC
Honored Contributor

Re: Checking for Links

George,

Don't worry, rm on an inode which is a symbolic link will remove the symbolic link not the file itself

Eric