List directories that are no target of a symlink

Viewed 66

Using Bash shell.

I have a directory with a large number of subdirectories.

Symbolic links points to some them. This makes managing the content quite convenient because the symlinks have more expressive names than the directory names.

For some other directories, this redirection job is still incomplete.

Is there a Bash way to list the directories that are no target of a symlink (contained in the same parent folder, if this simplifies the matter)? To me this would return the directories that I have still to work on and spare some error-prone donkey work.

1 Answers

Solution requires GNU CoreUtils:

#!/usr/bin/env sh

{
  # Create a list of null delimited symbolic links destination
  find . -type l -printf ./%l\\0

  # Append directories to the null delimited list
  find . -type d -print0
} |

# Sort the null delimited list
sort -z |

# Extract unique entries (those having no symbolic link)
uniq -zu |

# Produce a human-readable list by replacing null delimiters by newlines
xargs -0l
Related