NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: geting some file stat



Thanks all for your help,

indeed 
stat -f "%Mp%Lp:%u:%g:%N"
does the trick

On Tue, Feb 19, 2008 at 02:26:10PM -0600, Robby Griffin wrote:
> Don't forget you can stat multiple files, too:
>
> stat -f "%N %u %g %Mp%Lp" filename1 filename2 ...

but I have a *large* number of files.. and would expect a shell error
using them all on one line...


 store) 
        [ -z "$data_file" ] \
        && find ${root_dir} -type f \
                -exec stat -f "%Mp%Lp:%u:%g:%N" \{\} \; \
        || find ${root_dir} -type f \
                -exec stat -f "%Mp%Lp:%u:%g:%N" \{\} \; >"$data_file"
 ;;
 restore)
        cutf () { # Extract a particular field from a delimited line
                echo "${2%%#*}" | cut -d: -f${1} ;}
        # restore or display error
        cd ${root_dir}
        [ -z "$data_file" ] && data_file=/dev/stdin
        while read line ; do
                file="$(cutf 4 "$line")"
                mod="$(cutf 1 "$line")"
                user="$(cutf 2 "$line")"
                group="$(cutf 3 "$line")"
                [ -f "$file" ] && {
                        chmod $mod $file || { echo "ERROR: chmod $mod $file" 
>/dev/stderr ;}
                        chown $user:$group $file || { echo "ERROR: chown 
$user:$group $file" >/dev/stderr ;}
                        }
        done <${data_file}
 ;;

seems to work as expected, note only regular files are treated.

// George


-- 
George Georgalis, information system scientist <IXOYE><


Home | Main Index | Thread Index | Old Index