Skip to main content
added 560 characters in body
Source Link

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 the source, and /some/path/ is the destination. 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.

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:

  • 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.

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 the source, and /some/path/ is the destination. 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.

added 307 characters in body
Source Link

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:

  • 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.

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!

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:

  • 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.

Source Link

How to allow spaces in directories when using find -exec together with basename?

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!