On Mon, Jun 12, 2023 at 09:35:13PM +0000, bw wrote:
> Right now I'm studying and trying to come up with a way to identify duplicate
> filenames and/or symlinks between /bin /sbin /lib, and /usr/bin /usr/sbin
> /usr/lib.  I bet someone on the list could do it in a one line command.

Well, it's not *that* simple.  Bear in mind that the files in question
are not directly inside /lib and /usr/lib, but instead are inside
subdirectories (e.g. /lib/x86_64-linux-gnu).  So there has to be a
recursive discovery component.

Something like this might work as a starting point.  Note that it
assumes duplicate filename entries will be encountered in pairs, not
in larger groups.  I can't vouch for how well it'll handle finding 3 or
more of the same name.

I'm also not sure if the list of starting directories in the findem
function is complete.

#!/bin/bash

findem() {
    find /bin /lib /lib32 /lib64 /sbin /usr/bin /usr/lib /usr/lib32 \
        /usr/lib64 /usr/sbin \( -type f -o -type l \) -print0
}
declare -A found

while IFS= read -rd '' f; do
    name=${f##*/}
    if [[ ${found[x$name]} ]]; then
        printf '%s\n' "$f" "${found[x$name]}"
    fi
    found[x$name]=$f
done < <(findem)

Reply via email to