So I basically have a directory A that always exists. I'd like to replace this directory with a symbolik link (this will be done in my deployment script).
I've tried ln -sf app/cache A
but it does not work, it creates it inside A instead of overwriting it.
$ tree
.
├── A
│ └── cache -> app/cache
└── app
└── cache
3 directories, 1 file
Is it possible with only ln
or do I have to remove A beforehand?
The ln
utility may be asked to remove the destination if it already exists by adding the -f
option. However, the POSIX standard says that this is done with a call to the C library routine unlink()
, and about that function, the standard says
The
path
argument shall not name a directory unless the process has appropriate privileges and the implementation supports usingunlink()
on directories.
I have not access to a system where unlink()
is documented to remove directories, or where the -f
flag to ln
is documented to remove directories.
Your solution is therefore to either
$ rm -rf /path/to/A
or, which would be safer,
$ mv -f /path/to/A /path/to/A.orig
before creating the symbolic link.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With