exam questions

Exam XK0-005 All Questions

View all questions & answers for the XK0-005 exam

Exam XK0-005 topic 1 question 6 discussion

Actual exam question from CompTIA's XK0-005
Question #: 6
Topic #: 1
[All XK0-005 Questions]

A user is asking the systems administrator for assistance with writing a script to verify whether a file exists. Given the following:

Which of the following commands should replace the <CONDITIONAL> string?

  • A. if [ -f "$filename" ]; then
  • B. if [ -d "$filename" ]; then
  • C. if [ -f "$filename" ] then
  • D. if [ -f "$filename" ]; while
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Veteran903
Highly Voted 12 months ago
please correct the mistake, right after the hashtag should be a bang(!) and not a number 1
upvoted 16 times
...
linux_admin
Highly Voted 8 months, 4 weeks ago
he command "if [ -f "$filename" ]; then" is a shell script that tests for the existence of a file named "$filename". The syntax of this command is as follows: "if" is a shell construct that allows you to execute a command or a series of commands only if a certain condition is met. "[ -f "$filename" ]" is a test command that returns true if "$filename" is a regular file (i.e., not a directory or a symbolic link). The "-f" option is used to test for the existence of a regular file. The "$filename" variable is enclosed in double quotes to allow for the possibility of spaces in the file name. "then" is a keyword that specifies the start of the commands to be executed if the test is true.
upvoted 9 times
...
MrJ_
Most Recent 9 months ago
Answer must be A -f file True if file exists and is a regular file THEN
upvoted 3 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago