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?
Click on the arrows to vote for the correct answer
A. B. C. D.A.
The correct shell script that will accomplish the task of finding files and subdirectories in the /etc directory that contain the word services
and list them alphabetically in the /var/tmp/foundservices file is option D.
Here's a detailed explanation of why the other options are incorrect:
Option A: #/bin/bash find /etc "name services | sort > /var/tmp/foundservices This script has syntax errors. The find
command is not correctly formatted. The -name
parameter is missing, which is used to specify the name of the file or directory to search for. Also, the |
character should be outside the quotes. The sort
command should also be placed before the redirection operator >
. The correct script should be:
bash#!/bin/bash find /etc -name "*services*" | sort > /var/tmp/foundservices
Option B: #/bin/bash locate /etc "sort "name services > /var/tmp/foundservices This script is also incorrect. The locate
command is not used to search for files and directories. It is used to search a pre-built database of files on the system. Also, the sort
command is incorrectly placed before the |
character. The correct script should be:
bash#!/bin/bash find /etc -name "*services*" | sort > /var/tmp/foundservices
Option C: #/bin/bash find "name services "sort </var/tmp/foundservices This script has multiple syntax errors. The find
command is not correctly formatted, and the sort
command is also not correctly placed. The <
operator should be outside the quotes. The correct script should be:
bash#!/bin/bash find /etc -name "*services*" | sort > /var/tmp/foundservices
Option D: #/bin/bash find /etc "name services "sort > /var/tmp/foundservices. This script is correct. The find
command is used to search for files and directories in the /etc directory that contain the word services
. The -name
parameter is correctly used to specify the name of the file or directory to search for. The sort
command is also correctly placed after the |
character and before the redirection operator >
. The correct script is:
bash#!/bin/bash find /etc -name "*services*" | sort > /var/tmp/foundservices
In summary, the correct script to accomplish the task is:
bash#!/bin/bash find /etc -name "*services*" | sort > /var/tmp/foundservices