ExamGecko
Question list
Search
Search

List of questions

Search

Related questions











Question 301 - SK0-005 discussion

Report
Export

A server administrator is creating a script that will move files only if they were created before a date input by the user. Which of the following constructs will allow the script to apply this test until all available files are assessed?

A.
Variable
Answers
A.
Variable
B.
Loop
Answers
B.
Loop
C.
Comparator
Answers
C.
Comparator
D.
Conditional
Answers
D.
Conditional
Suggested answer: B

Explanation:

A loop is a script construct that allows the script to repeat a block of code until a certain condition is met or for a specified number of times. A loop can be used to apply a test to each file in a directory and move the files that meet the criteria. For example, in a bash script, a loop can be written as:

#!/bin/bash

# Ask the user for the date

echo "Enter the date (YYYY-MM-DD):"

read date

# Loop through all the files in the current directory

for file in *

do

# Check if the file was created before the date

if [[ $(date -r "$file" +%F) < $date ]]

then

# Move the file to another location

mv "$file" /path/to/destination

fi

done

Copy

A variable is a script construct that allows the script to store and manipulate data. A variable can be used to store the date input by the user, but it cannot apply a test to each file1

A comparator is a script construct that allows the script to compare two values and determine their relationship. A comparator can be used to check if a file was created before the date, but it cannot repeat the test for all files1

A conditional is a script construct that allows the script to execute different blocks of code based on certain conditions. A conditional can be used to decide whether to move a file or not, but it cannot iterate over all files1

1: CompTIA Server+ Certification Exam Objectives

asked 02/10/2024
Robbie Shen
34 questions
User
Your answer:
0 comments
Sorted by

Leave a comment first