XK0-005 · Question #102
A Linux administrator wants to obtain a list of files and subdirectories in the /etc directory that contain the word "services". Once the files and subdirectories are discovered, they should be…
The correct answer is A. #/bin/bash. To find files and directories containing 'services' within /etc, then list them alphabetically in /var/tmp/foundservices, a script must combine content and name searches, then sort the results.
Question
A Linux administrator wants to obtain a list of files and subdirectories in the /etc directory that contain the word "services". Once the files and subdirectories are discovered, they should be listed alphabetically in the /var/tmp/foundservices file. Which of the following shell scripts will accomplish this task?
Options
- A#/bin/bash
- B#/bin/bash
- C#/bin/bash
- D#/bin/bash
How the community answered
(33 responses)- A76% (25)
- B12% (4)
- C3% (1)
- D9% (3)
Why each option
To find files and directories containing 'services' within `/etc`, then list them alphabetically in `/var/tmp/foundservices`, a script must combine content and name searches, then sort the results.
The correct shell script would typically involve a combination of `grep -rl "services" /etc` to recursively find files whose *content* includes "services", and `find /etc -type d -name "*services*"` to locate directories whose *names* contain "services". The output from both commands would then be piped to `sort` for alphabetical ordering and finally redirected (`>`) into the specified `/var/tmp/foundservices` file, ensuring all relevant items are captured and correctly formatted.
Without the actual script content for option B, it is impossible to identify specific technical reasons for it being wrong.
Without the actual script content for option C, it is impossible to identify specific technical reasons for it being wrong.
Without the actual script content for option D, it is impossible to identify specific technical reasons for it being wrong.
Concept tested: Linux file/directory searching and sorting with `grep` and `find`
Source: https://man7.org/linux/manpages/man1/grep.1.html
Topics
Community Discussion
No community discussion yet for this question.