I have a bash script that creates symlinks from the directories in one users directory to another users directory. I want the script to exclude existing symlinks in the source directory when creating symlinks.

  • Looks like you're reinventing stow – muru Apr 8 at 10:08
  • Thanks, I am not familiar with stow, is that similar to "install"? Also, I am on MacOs, so stow is not available for me right now. I will check it out. – David Norden Apr 8 at 10:24
  • stow is much more. It's used for managing symlinks to files from one directory to another. Lets you add, update, remove groups of symlinks. It's available via homebrew. – muru Apr 8 at 10:29
  • I think I have to find another approach. Is there a way to find and remove files with a pattern like this (where the pattern is only that there are two underscores in the filename, separated by letters or numbers) file_name_name – David Norden Apr 8 at 14:48

you can simply use the -L operator.

user@debian:~$ touch file
user@debian:~$ ln -s file link
user@debian:~$ ls -l
total 8
-rw-r--r-- 1 user user    0 avril  8 12:01 file
lrwxrwxrwx 1 user user    4 avril  8 12:01 link -> file
user@debian:~$ if [[ -L file ]]; then echo "it's a link"; fi
user@debian:~$ if [[ -L link ]]; then echo "it's a link"; fi
it's a link
  • Thanks, but it seems that option is not available on MacOS.. – David Norden Apr 8 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.