[nzlug] Any way to edit broken soft links?
Nic Bellamy
nic at bellamy.co.nz
Mon Dec 10 16:08:12 NZDT 2007
Raimund Eimann wrote:
> Hi,
>
> On Monday 10 December 2007, Martin Bähr wrote:
>
>> in that case you should be able to write a script:
>>
>> for each link:
>> read link target;
>> convert target to utf-8
>> replace link with new one to converted target.
>>
>
> I had a bad feeling that this might be the only way... :(
>
> Is there at least an easy way to get the link target or is it necessary to
> use "cut"?
>
About the closest you can get in pure shell is to use the 'stat'
command, eg.
$ ls -l
lrwxrwxrwx 1 owner group 26 2007-06-28 00:06 Examples ->
/usr/share/example-content
$ stat -c '%N' Examples
`Examples' -> `/usr/share/example-content'
But then you still have to parse the output from 'stat', which isn't
much better than parsing the output of 'ls'.
With a more powerful language, eg. Python, you can use the readlink
syscall and be a bit more direct:
$ python
>>> import os
>>> os.readlink('Examples')
'/usr/share/example-content'
>>>
Cheers,
Nic.
--
Nic Bellamy <nic at bellamy.co.nz>
More information about the NZLUG
mailing list