cancel
Showing results for 
Search instead for 
Did you mean: 

symlinks -r -d /

SOLVED
Go to solution
'chris'
Super Advisor

symlinks -r -d /

hi

what happens after this command:

# symlinks -r -d /

on linux ?

9 REPLIES
Steven Schweda
Honored Contributor
Solution

Re: symlinks -r -d /

"man symlinks"?

-d causes dangling links to be removed.

-r recursively operate on subdirectories within the same filesys-
tem.


"on linux" is not a very useful description
of the system.
'chris'
Super Advisor

Re: symlinks -r -d /

thanks, but what dangling links means ?
Steven Schweda
Honored Contributor

Re: symlinks -r -d /

> [...] but what dangling links means ?

I guess that it means that you didn't take
the "man symlinks" hint offered earlier.

"man symlinks":

dangling links are those for which the target of the link does not cur-
rently exist. This commonly occurs for absolute links when a filesys-
tem is mounted at other than its customary mount point (such as when
the normal root filesystem is mounted at /mnt after booting from alter-
native media).


For information on most commands, "man
command" is often helpful. In this case,
"man symlinks".

Did you try "man symlinks"?

"man symlinks" might help.
James R. Ferguson
Acclaimed Contributor

Re: symlinks -r -d /

Hi Chris:

A simple way to find dangling symbolic links is to use this Perl snippet:

# perl -MCwd=realpath -MFile::Find -wle 'find(sub{print $File::Find::name," -> ",realpath($_) if -l && ! -e},@ARGV)' /path

Pass the /path argument that represents the directory that you want to examine. If there are dangling links, this reports them. For example, do:

# touch /tmp/myfile
# ln -s /tmp/myfile /tmp/mylink
# rm /tmp/myfile
# perl ...
/tmp/mylink -> /tmp/myfile

...which exposes '/tmp/mylink' as a dangling symbolic link.

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: symlinks -r -d /

On HP-UX anyway, if you use "ls -lL" on a directory, any dangling link would have bogus permissions, owner, group and time. Then you could just grep for that pattern.
'chris'
Super Advisor

Re: symlinks -r -d /

thanks to ALL,

do I understand correct ?

symlinks -r -d /

cannot damage my linux system ?
Steven Schweda
Honored Contributor

Re: symlinks -r -d /

> [...] cannot damage my linux system ?

It _probably_ won't. I can _imagine_ someone
using a dangling link for data storage, like
a simple text file, so I wouldn't _guarantee_
that it's safe.

ln -s 'Any text may be stored here.' fred
symlinks .
dangling: /house/antinode/fred -> Any text may be stored here.

Have you looked at the output without "-d",
to see what will happen with "-d"?

If you have any doubts about the safety of
"symlinks -d", why do you want to do it?
Dennis Handly
Acclaimed Contributor

Re: symlinks -r -d /

>Steven: I can _imagine_ someone using a dangling link for data storage, so I wouldn't _guarantee_ that it's safe.

That's exactly what netscape does to prevent multiple instances. It has a .lock that is linked to the value of DISPLAY and maybe the PID.
James R. Ferguson
Acclaimed Contributor

Re: symlinks -r -d /

Hi (again) Chris:

> symlinks -r -d / ...cannot damage my linux system ?

If it is a *personal* system, then it's up to you to choose. If this is a company/production server, then I'd be a bit more careful.

Instead of capraciously removing all dangling links, I would do:

# symlinks -r / | grep dangling

...and exaxmine the output. Then, perhaps on a case-by-case basis make a determination to manually remove ('rm') dangling links that you don't want.

A dangling link isn't necessarily a "bad thing". For instance, you might want to keep symbolic links to an installation CD/DVD/USB. I might have:

# symlinks -r /home
dangling: /home/jrf/install -> /media/JRF_DISK/ARCHIVE.tar

...which I might wish to retain for times when I actuall mount a USB device named "JRF_DISK".

Regards!

...JRF...