LFCS · Question #861
Which of the following commands prints all files and directories within the /tmp directory or its subdirectories which are also owned by the user root? (Choose TWO correct answers.)
The correct answer is C. find /tmp -user root -print D. find /tmp -user root. The find command is used to locate files and directories within a specified path based on various criteria, including ownership, and will print the results.
Question
Options
- Afind /tmp -uid root -print
- Bfind -path /tmp -uid root
- Cfind /tmp -user root -print
- Dfind /tmp -user root
- Efind -path /tmp -user root print
How the community answered
(36 responses)- A6% (2)
- B3% (1)
- C92% (33)
Why each option
The `find` command is used to locate files and directories within a specified path based on various criteria, including ownership, and will print the results.
The `-uid` option for the `find` command expects a numeric User ID (UID), not a username like `root`, so this command would not correctly identify files by username.
The `-path` option is used to match a specific path pattern, not to specify the starting directory for the search; the starting directory (`/tmp`) must be the first argument to `find`, and `-uid` requires a numeric ID.
The command `find /tmp -user root -print` correctly searches the `/tmp` directory and its subdirectories, identifying all files and directories owned by the `root` user, and then explicitly prints their paths to standard output.
The command `find /tmp -user root` is also correct because the `find` command, by default, performs the `-print` action if no other action (like `-exec` or `-delete`) is specified, making it functionally equivalent to explicitly including `-print` for this purpose.
The `-path` option is incorrectly used here for specifying the starting directory, and the `print` action is misplaced as it should typically be preceded by a hyphen or be implicitly called as a default action.
Concept tested: find command by user ownership
Source: https://man7.org/linux/man-pages/man1/find.1.html
Topics
Community Discussion
No community discussion yet for this question.