command line - Filter files according to owner under same directory - Ask Ubuntu
i writing script has common directory , under directory there files different owners.
how can filter files according owner files , parse them separately owner name filename:
/gen/comm_owner/a /gen/comm_owner/b there more 20 owners more 60 files. expected output gen/comm_owner/a.txt, a.txt contains files, likewise b.txt. have tried awk , sed , able filter things how perform this?
find /some/path -type f -printf "%u/%p\n" | awk -f/ '{u=$1; sub($1"/", ""); print > u}' find's-printfoption powerful. in case, tell print username , relative file path separated slash (e.g.,muru/foo/bar(or use%pinstead of%p,muru//some/path/foo/bar).- then, in
awk, splitting on/, save first field (the username), remove input, , print input username.
example:
$ find /var/lib -type f -printf "%u/%p\n" | awk -f/ '{u=$1; sub($1"/", ""); print > u}' $ ls colord nobody ntp ptokax root systemd-timesync $ head ntp /var/lib/ntp/ntp.drift $ head nobody /var/lib/nfs/state $ head root /var/lib/dbus/machine-id /var/lib/os-prober/labels /var/lib/xkb/readme.compiled /var/lib/logrotate.status /var/lib/nfs/rmtab
Comments
Post a Comment