Is there a flag you can add to the ln
command to force the creation of the target directory structure (like mkdir -p
).
Consider :
ln -s /Applications/'Sublime Text.app'/Contents/SharedSupport/bin/subl /usr/local/bin/
Which adds a symlink to the Sublime Text command line tool. But it fails if /usr/local/bin/ doesn't exist.
I've tried the -f
'force' flag but that doesn't help.
Do you need to test wether /usr/local/bin/ exists and create it if it doesn't before running the ln
command or is there a fancier way to do it?
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.
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