exam questions

Exam XK0-005 All Questions

View all questions & answers for the XK0-005 exam

Exam XK0-005 topic 1 question 40 discussion

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

A Linux administrator was tasked with deleting all files and directories with names that are contained in the sobelete.txt file. Which of the following commands will accomplish this task?

  • A. xargs -f cat toDelete.txt -rm
  • B. rm -d -r -f toDelete.txt
  • C. cat toDelete.txt | rm -frd
  • D. cat toDelete.txt | xargs rm -rf
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

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
linux_admin
Highly Voted 1 year, 9 months ago
Selected Answer: D
D. cat toDelete.txt | xargs rm -rf The "cat toDelete.txt" command will display the contents of the "toDelete.txt" file, which contains the names of the files and directories to be deleted. The "xargs rm -rf" command will take the standard input from the "cat" command and pass it as arguments to the "rm" command. The "-rf" options of the "rm" command are used to forcibly delete the specified files and directories, including any files and directories within them, even if they are write-protected. The "xargs" command is used here to process the input one line at a time and execute the "rm" command for each line.
upvoted 7 times
...
bc1235813
Most Recent 8 months ago
Selected Answer: D
The rm command will do nothing to act on the contents of the file without help. As written rm will remove the file in question. You need to expose the contents of the file to rm in order for it to act on them. Either cat the file and hand it off to xargs or "xargs rm -rf < file" or cat it , send it to awk and let awk pass the contents to rm.
upvoted 1 times
...
e418137
9 months ago
Selected Answer: D
D. `xargs` builds and executes command lines from standard input. Assuming the file, toDelete.txt, contains one file name per line, this works. The other answers are nonsense.
upvoted 1 times
...
Nvoid
1 year, 11 months ago
Selected Answer: D
mod correct, the question states "sobelete.txt" and should say "toDelete.txt".
upvoted 3 times
Nvoid
1 year, 11 months ago
mod correct, the answer id D.
upvoted 2 times
...
...
ryanzou
2 years ago
Selected Answer: D
Definitely is D
upvoted 1 times
...
TheRealManish
2 years ago
Selected Answer: D
Tested, confirmed D is correct
upvoted 3 times
...
Aamm033
2 years ago
Selected Answer: D
D is the correct answer. The selected answer delete the file. with answer D it removes the files listed inside the file. xargs - build and execute command lines from standard input.
upvoted 3 times
...
bjornborg
2 years ago
I'm pretty sure this one is D. Option B just removes the file, but the question asks to remove files & directories "listed inside" the file. Just tested this out on my Linux machine ... It's D
upvoted 1 times
Veteran903
1 year, 12 months ago
I didn't know one can have a directory inside a file, I thought it was the other way around, directories can contains file but file cannot contain directories, actually as B option states if you provide the options listed you can accomplish the task with no problem, i just tested it and it works fine.
upvoted 2 times
Nvoid
1 year, 11 months ago
i think your getting muxed up, the "directory" is just a location inside the file "toDelete.txt".
upvoted 2 times
Veteran903
1 year, 11 months ago
No, a directory is always a directory, i tested B with all the options and it works perfect on centOS 9
upvoted 1 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