I'm trying to find all the directories in a given path, and create soft links inside those directories into directories with the same names at another location. Many of the directories have spaces in their names. I have cobbled the following code together, and it seems to work provided there are no spaces.
find /some/path/* -maxdepth 0 -exec sh -c "ln -s /some/other/path/"'$(basename {})'" {}" \;
How should I change this to handle spaces? I normally don't have them in my directory names, but these mirror directories on my Windows PC, where I do use spaces. Any help is greatly appreciated!
EDIT
In response to the points made by cuonglm and Gilles:
The order of the
ln -s
command arguments is not mistaken, but what I wanted to do is not quite clear from my explanation. For every directory in/some/path/
, I want to create a symbolic link in that directory pointed at a directory with the same name in/some/other/path/
. So/some/other/path/
is thesource
, and/some/path/
is thedestination
. The reason I want to do this is because/some/path/
contains a subset of the directories in/some/other/path/
, and I want a link from the subset to the full set for every directory.There won't be too many directories in the path, but I agree that not guarding against it is a pointless flaw.
The reason I didn't use
-type d
is that there will only be directories and not files in the given path, but I realise including it is better.
/some/path/*
and try to create symbolic links in place of those very files - second argument ofln -s
. You will surely getFile exists
error./some/path/test
and run theln -s
command twice, then the first link will be/some/path/test
, but the second will be/some/path/test/target
.