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
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$
Give this a try:
ln -s /foo/* /bar
The source directory, as specified in the question, is /foo
. Note that it must be fully specified (i.e. starting at the root directory), so other examples would look like this:
ln -s /some/dir/with/baz/* destdir
ln -s /dir/to/link/from/* /dir/to/link/to
ln -s $PWD/stuff/* more/stuff
/
in my original answer). I'll add a clarification.
Aug 3, 2015 at 18:14
cp -rs /var/www/folder/ .
copies every subfolders files as symlink, not like ln -s /var/www/folder/ .
who duplicated subfolders files on my computer.
ln -s /foo/.* /bar
.
--prefix=
.