Pseudocode
ln -s $HOME/file $HOME/Documents/ $HOME/Desktop/
where I want to create a symlink from the source to two destinations.
Probably, moreutils
and pee
.
How can you create many symlinks from one source?
Pseudocode
ln -s $HOME/file $HOME/Documents/ $HOME/Desktop/
where I want to create a symlink from the source to two destinations.
Probably, moreutils
and pee
.
How can you create many symlinks from one source?
You can't do this with a single invocation of ln
,but you could loop through all necessary destinations:
$ for i in "$HOME/Documents/" "$HOME/Desktop/"; do ln -s "$HOME/file" "$i"; done
If you have gnu parallel
you could try with
parallel ln -s /path/file {} ::: /path/dest1 /path/dest2 /path/dest3
or, to symlink multiple targets to (the same) multiple destinations
parallel ln -s {1} {2} ::: /path/file1 /path/file2 ::: /path/dest1 /path/dest2
parallel
command from the parallel
package and not the one from moreutils
.
– Gilles 'SO- stop being evil'
Jun 01 '16 at 22:27
It's no less verbose than two separate ln -s
invocations:
echo $HOME/Documents/ $HOME/Desktop/ | xargs -n 1 ln -s $HOME/file
but that only works for absolute paths (because symbolic links are interpreted relative to their parent directory, unless they're absolute).
(The relative cost drops of course as the number of links goes up. Also, this snippet relies on the fact that $HOME
doesn't contain any spaces, tabs or newlines.)