Right now I use this

ln -s /dir/* /dir2/

Which will symlink everything, but I have to go inside the dir and make a new directory because the folders are also symlinked (this is expected).

So here is what Im trying to achieve: Symlink all files, but when there is a folder, make a directory with the same name and symlink the files inside of that folder and inside that folder, etc.

Much like GNU cp with the -al flag, which I got by running brew install coreutils.

gcp -al /dir1/ dir2/ 

This does what I want except they are hard links and not symlinks.

  • gcp -as (only works with absolute paths though). Dec 1, 2014 at 11:08

1 Answer 1


I guess you should separate the file handling from the directory handling. Make the directories first. In the GNU world:

cd /dir2
find /dir -mindepth 1 -maxdepth 1 -type d -exec mkdir {} \;

And then the symlinks:

find /dir -mindepth 1 -maxdepth 1 -type f -exec ln -s -t /dir2 {} +
  • Drop -maxdepth 1 since the copy should recurse. mkdir {} is wrong: you're attempting to create directories that already exist. You need to translate /dir into /dir2 in the paths. Dec 2, 2014 at 14:29

You must log in to answer this question.

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