1

I have directory scalable for vector icon theme and I have bunch of symlinks in there which I want to replace by a file that contain names that I can use with ln command, I've create the file it contain lines that look like this:

scalable/actions/messagebox_warning.svg scalable/emblems/emblem-danger.svg
scalable/emblems/emblem-nowrite.svg scalable/emblems/emblem-unreadable.svg
scalable/distributor-logos/debian.svg scalable/emblems/Debian.svg
scalable/mimetypes/gnome-mime-text-plain.svg scalable/emblems/emblem-documents.svg
scalable/emblems/emblem-personal.svg scalable/emblems/emblem-readonly.svg
scalable/mimetypes/package-x-generic.svg scalable/emblems/emblem-package.svg
scalable/apps/download.svg scalable/emblems/emblem-downloads.svg
scalable/devices/network-wired.svg scalable/emblems/emblem-shared.svg
scalable/distributor-logos/ubuntu.svg scalable/emblems/emblem-ubuntu.svg

I've try to use this command:

xargs -L 1 ln -sf < src/symlinks

also try this:

xargs -L 1 -I{} ln -sf {} < src/symlinks

but it created symlinks that point to themself. How can I create symlinks where desination in filename are taken from file?

2 Answers 2

3

Assuming your file is in the right order (target, then link name), and that no filename contains special characters or spaces:

sed 's/^/ln -sf /g' < src/symlinks | sh

will transform your list of symlinks into a series of ln -sf commands and run it using sh.

3
  • I think that sed will not work without -e option.
    – jcubic
    Dec 27, 2016 at 22:50
  • @jcubic It will if there is only a single sed script (that unit that runs over your input once).
    – phk
    Dec 27, 2016 at 22:51
  • Oh, good to know.
    – jcubic
    Dec 27, 2016 at 22:59
0

Solution using a while loop, under the assumption that the paths don't have spaces or newlines in them:

while IFS=' ' read -r t l; do ln -sf -- "$t" "$l"; done < src/symlinks

You must log in to answer this question.

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