[Liverpool] batch-edit symlinks

Daniel Hulme lpool-lug at istic.org
Fri Mar 2 22:01:53 GMT 2007


On Fri, Mar 02, 2007 at 09:07:36PM +0000, Neil Bothwick wrote:
> Something like this should work, but I haven't tested it
> 
> find /some/path -type l | while read LINK; do
> 	TARGET=$(readlink $LINK)
> 	ln -sf "${LINK/old\/dir/new\/dir/}" "$TARGET"
> 	done
I spotted the deliberate mistake: the second-last line should read

ln -sf "${TARGET/old\/dir/new\/dir/}" "$LINK"

(that is, LINK and TARGET should be the other way around).

Thanks for the tip, Neil. I didn't know about the readlink command. I
thought I was going to have to resort to a Perl script -- probably a
one-line Perl script, but still more work than it needed to take.

-- 
Hats are no worse for being made by ancient hatters, and good butter can
be bought in a shop that has no jazz-band.  -- J.B. Morton (Beachcomber)
P.S. --- Tell  Saunders that he  must not leave cat's  meat on  my desk.
http://surreal.istic.org/ old-fashioned quality within the McQuary limit
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.lug.org.uk/pipermail/liverpool/attachments/20070302/3064b112/attachment.bin


More information about the Liverpool mailing list