How to create a symbolic link when target directory doesn't exist?
Try like this,
mkdir -p /create_your_path/ && xargs ln -s /link_file_path/file /create_your_path/
Nope, there is no standard option to ln
to create a missing target directory. Use install
or mkdir -p
before ln
, perhaps in a helper script if you find you need this more than once.
#!/bin/bash -e
mkdir -p "${!#}"
exec ln -s "$@"
This is obviously not very robust, but feel free to embellish it with more sanity checks if you think you really find it useful.