If I have a directory /foo with a few files in it, how do I symlink each entry in /foo into /bar/?

For instance, if /foo has the files a, b and c, I want to create three symlinks:

  • /bar/a -> /foo/a
  • /bar/b -> /foo/b
  • /bar/c -> /foo/c
link|improve this question
Are you sure you don't just want to symlink bar to foo? – Rich Bradshaw Feb 11 '11 at 17:18
The actual application of this is that I installed a program and would like to move its executables to a standard folder in my $PATH rather than add the installed one to the path. – Steven Xu Feb 11 '11 at 17:21
It seems like it would be a better idea to just configure it with --prefix=. – Hello71 Feb 12 '11 at 18:15
feedback

3 Answers

up vote 1 down vote accepted

You can use (GNU) cp with the --symbolic-link option:

prompt$ mkdir foo
prompt$ cd foo
prompt$ touch a b c
prompt$ mkdir ../bar
prompt$ cd ../bar
prompt$ cp --symbolic-link ../foo/* .
prompt$ ls -l
total 0
lrwxrwxrwx. 1 hlovdal hlovdal 8 Jun 12 16:24 a -> ../foo/a
lrwxrwxrwx. 1 hlovdal hlovdal 8 Jun 12 16:24 b -> ../foo/b
lrwxrwxrwx. 1 hlovdal hlovdal 8 Jun 12 16:24 c -> ../foo/c
prompt$
link|improve this answer
This seems to be exactly the solution. Awesome! – Steven Xu Jun 12 '11 at 16:07
feedback

Give this a try:

ln -s /foo/* /bar
link|improve this answer
feedback

Something like this?

cd /foo
for f in *; do ln -s $PWD/$f /bar; done
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.