nerdexam
CompTIA

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.

Scripting, Containers, and Automation

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)
  • A
    76% (25)
  • B
    12% (4)
  • C
    3% (1)
  • D
    9% (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.

A#/bin/bashCorrect

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.

B#/bin/bash

Without the actual script content for option B, it is impossible to identify specific technical reasons for it being wrong.

C#/bin/bash

Without the actual script content for option C, it is impossible to identify specific technical reasons for it being wrong.

D#/bin/bash

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

#Shell Scripting#Linux Commands#File System Navigation#Text Processing

Community Discussion

No community discussion yet for this question.

Full XK0-005 Practice