Find regular files under /srv/data owned by alice.
Which GNU find command is appropriate?
find -user NAME tests the owning user; -group tests the owning group and -name tests the filename.
Detailed explanation
find /srv/data -type f -group aliceIncorrect. -group alice tests the group name.
find /srv/data -type f -name aliceIncorrect. -name alice tests the file name.
find /srv/data -type f -user aliceCorrect. find /srv/data -type f -user alice selects alice-owned regular files.
find /srv/data -type f -perm aliceIncorrect. -perm tests mode bits rather than an owner name.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp -d); touch "$tmp/mine"; find "$tmp" -type f -user "$(id -un)" -printf '%f\n'; rm -rf "$tmp"Expected result
mineKey points
- -user is owner
- -group is owning group
- -name is filename
Notes
- Environment: GNU findutils 4.x / 現在の利用者が所有する一時ファイル
- Use disposable files and directories for destructive or timestamp-related checks.
- Command details can vary slightly between GNU and non-GNU implementations.
Foundation review
Place the operation
Ownership tests inspect metadata associated with the object; name and permission tests inspect different fields.
Check the side effect
Verify the owner with a metadata listing before relying on a name-to-ID lookup.