Satya's blog - Going from Windows shortcut .lnk to nix symlink

Nov 28 2005 09:57 Going from Windows shortcut .lnk to nix symlink
So I had a bunch of shortcuts to images on my Windows box. After scping them to Linux, I had a bunch of lnk files that had nothing to do with the original files. And binary. So I whipped up a short shell command:
for i in *.lnk
do echo ln -s `grep -ao [a-zA-Z0-9_]*.jpg $i` $i
piped the output of that to, edited it in vim to prepend ../ (if needed; my original images were in the parent directory) and remove the trailing .lnk from each line. Then I ran the shell script and voila, I have symlinks next to windows lnk files (in case I scp them back to a Windows box). These are archival files so there's no question of frequent updates.

The grep command works with an 'a' for text-mode, 'o' to return just the matched parts (the lnk file contains a full Windows-style path), and the regex matches the filename: any-case letters, number, underline. I know the filenames are limited to that.

Tag: geeky code