Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
share|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

3 Answers 3

up vote 7 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
share|improve this answer
This seems to be exactly the solution. Awesome! –  Steven Xu Jun 12 '11 at 16:07

Something like this?

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

Give this a try:

ln -s /foo/* /bar
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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