user14510150
user14510150

Reputation: 77

How to force "ln --symbolic" as --force does not work?

I am trying to do a ln -symbolyc link for all the .* files.

The problem is that it works first time, but second time it fails, and it looks that --force does not work

This is the code:

ln --symbolic --relative --force ./websites/web1es/.* ./websites/webtable/

This is the error:

ln: ./websites/webtable/.: cannot overwrite directory
ln: './websites/web1es/..' and './websites/webtable/..' are the same file

Does anyone have any idea?

Thanks a lot in advance for any clue!

Upvotes: 0

Views: 975

Answers (1)

bk2204
bk2204

Reputation: 76539

When you specify .* in the shell, that includes . and ... If you specify a directory as the last argument, all the input files are linked into the destination directory with their same name as in the source directory.

As a result, your script is linking ./websites/web1es/.. to ./websites/webtable/... Unfortunately, the latter exists and is the parent directory of both directories, so deleting it is not possible. Moreover, as ln is telling you, the source and destination are the same file (or, in this case, directory), so even if ln could delete the destination, you'd experience data loss by doing so, so it's refusing.

Your solution should be to avoid handling . and ... For example, you could write this:

find ./websites/web1es -mindepth 1 -maxdepth 1 -name '.*' -print0 | \
     xargs -0 -I {} ln -srf {} ./website/webtable

find does not enumerate . and .. here.

Upvotes: 1

Related Questions