I am root. I would like to know whether a non-root user has write access to some files - thousands of them. How to do it efficiently while avoiding process creation?
Find files that a user can write, efficiently with minimal process creation
shell;files;permissions;users
Perhaps like this:#! /bin/bashwritable(){    local uid=$1    local gids=$2    local ids    local perms    ids=($( stat -L -c '%u %g %a' -- $3 ))    perms=0${ids[2]}    if [[ ${ids[0]} -eq $uid ]]; then        return $(( ( perms & 0200 ) == 0 ))    elif [[ $gids =~ (^|[[:space:]])${ids[1]}($|[[:space:]]) ]]; then        return $(( ( perms & 020 ) == 0 ))    else        return $(( ( perms & 2 ) == 0 ))    fi}user=foouid=$( id -u $user )gids=$( id -G $user )while IFS= read -r f; do    writable $uid $gids $f && printf '%s writable\n' $fdoneThe above runs a single external program for each file, namely stat(1).Note: This assumes bash(1), and the Linux incarnation of stat(1).Note 2: Please read comments from Stphane Chazelas below for past, present, future, and potential dangers and limitations of this approach.