-2

I'm trying to make a symlink to a directory if it exists only and cannot figure out how.

I tried various ideas I found and none worked. Most notable idea that i thought would do the job was to use ln -s ls /path to test the dir for ln but it did not work or I'm not doing it right.

This is the basic symlink command I'm trying to condition.

ln -s ~/public_html/images ./images
transilvlad
  • 173
  • 14

2 Answers2

2
[ -d ~/public_html/images ] && ln -s ~/public_html/images ./images
jj33
  • 11,038
  • 1
  • 36
  • 50
0

On Ubuntu use

ls ./public_html/images && ln -s ~/public_html/images ./images

The first command (list content of ./public_html/images) will fail if ./public_html/images does not exist. Due to double ampersand (&&) the second command (create soft link) will only run if first command succeeds.