Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a couple of soft symbolic links that have lost their link status and have become normal files containing

link TARGET_FILE_LOCATION

I searched quite a bit to find a way to restore their link status but couldn't find any.

share|improve this question

closed as unclear what you're asking by Tog, ϺОŞΣŞ, Dave M, Flimzy, Carl B Nov 14 '13 at 6:55

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer 1

You can fix this with a trivial Perl script:

#!/usr/bin/perl

use strict;
my $progname = $0; $progname =~ s@^.*/@@;

# accept path of bogued "link" file on command line
my $file = shift()
  or die "$progname: usage: $progname <file>\n";

my $content = '';
my $target = '';

# read the bogued file to find out where the symlink should point
open my $fh, '<', $file
  or die "$progname: unable to open $file: $!\n";

# parse the target path out of the file content
$content = <$fh>;
die "$progname: $file content in bogus format\n"
  unless $content =~ m@^link (.*)\r?\n$@;
$target = $1;

close $fh;

# delete the bogued file
unlink $file
  or die "$progname: unable to unlink $file: $!\n";

# replace it with the correct symlink
system('ln', '-s', $target, $file);

Drop the script into a file e.g. fixlink.pl, then invoke it as perl fixlink.pl /path/to/bogued/symlink, and it will read the target out of the file and then replace the file with a symlink to that target.

Of course, this does nothing to address whatever's actually causing the problem, but it should at least make life simpler until you've been able to work out the cause and correct it.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.