I have this folder structure:
build.1 build.2 build.3 build.4 current -> symlink to build.4 previous -> symlink to build.3
I am running debian, what is the proper way to delete every build (=folder) which has no symlink to it?
As Bron as said, there is no official way of doing it (more strongly: there cannot be one due to the filesystem design, you can only roll your own). This would be how I would script it in bash (assuming the current structure, the
Not so much a "proper" way, but how often are you doing it? My usual approach would be to run up a small piece of Perl (choose your own poison) which read the directory contents, examined the symlinks, and built a list of directories to delete.
There's no metadata on the destination of a symlink that will tell you it's being linked to.
You'll want to take care about race conditions too - if a separate task is updating the symlinks, you don't want to delete the new directory before it gets linked!