A company policy requires that when a user is deleted, all files owned by that user in /home should be reassigned to a 'guest' account. Which command accomplishes this?
Trap 1: usermod -l guest olduser
usermod -l guest olduser only changes the login name in /etc/passwd; it does not alter the UID, and file ownership is tracked by UID, not by the login name. Files previously owned by olduser therefore remain associated with olduser's numeric UID, and if that UID does not match guest's UID, no files are actually reassigned. Moreover, the command does not delete the account at all, so it fails the policy's requirement to reassign all files upon deletion.
Trap 2: userdel -r olduser
userdel -r olduser does the opposite of reassigning files: the -r flag removes the user's home directory contents and mail spool, permanently destroying those files. It does not hand ownership of any files to guest; instead, any files in that home directory are deleted, and files elsewhere under /home that were owned by olduser remain orphaned. This violates both the policy to reassign all files and common retention requirements, making it an incorrect choice.
Trap 3: rsync -a /home/olduser/ /home/guest/
rsync -a /home/olduser/ /home/guest/ creates a duplicate copy of olduser's home directory contents under /home/guest, but it leaves the original files untouched and still owned by olduser. Even if rsync runs as root and preserves ownership on the copy, the source files are not reassigned, and any files outside the home directory are not addressed at all. This approach is about copying data, not about reassigning ownership of existing files upon account deletion.
- A
usermod -l guest olduser
Why wrong: usermod -l guest olduser only changes the login name in /etc/passwd; it does not alter the UID, and file ownership is tracked by UID, not by the login name. Files previously owned by olduser therefore remain associated with olduser's numeric UID, and if that UID does not match guest's UID, no files are actually reassigned. Moreover, the command does not delete the account at all, so it fails the policy's requirement to reassign all files upon deletion.
- B
find /home -user olduser -exec chown guest {} +
find /home -user olduser -exec chown guest {} + is correct because it searches /home for every file whose owner matches the username olduser (which resolves to the UID) and executes chown guest on them in one batched command, thanks to the + terminator. This directly transfers ownership of each located file to guest, satisfying the policy efficiently. The find approach also covers files outside olduser's home directory that reside anywhere under /home, whereas other options only handle the home directory itself.
- C
userdel -r olduser
Why wrong: userdel -r olduser does the opposite of reassigning files: the -r flag removes the user's home directory contents and mail spool, permanently destroying those files. It does not hand ownership of any files to guest; instead, any files in that home directory are deleted, and files elsewhere under /home that were owned by olduser remain orphaned. This violates both the policy to reassign all files and common retention requirements, making it an incorrect choice.
- D
rsync -a /home/olduser/ /home/guest/
Why wrong: rsync -a /home/olduser/ /home/guest/ creates a duplicate copy of olduser's home directory contents under /home/guest, but it leaves the original files untouched and still owned by olduser. Even if rsync runs as root and preserves ownership on the copy, the source files are not reassigned, and any files outside the home directory are not addressed at all. This approach is about copying data, not about reassigning ownership of existing files upon account deletion.