1

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.

1 Answer 1

0

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.

Not the answer you're looking for? Browse other questions tagged .