nerdexam
CompTIACompTIA

XK0-005 · Question #261

XK0-005 Question #261: Real Exam Question with Answer & Explanation

The correct answer is A: cat /etc/resolv.conf > /home/user/newfile. To create a new file with the exact contents of an existing file, the cat command can be used to display the source file's content, and the output redirection operator > will save that content to the destination file.

System Management

Question

A Linux user needs to create a file named newfile in the home directory that mirrors the contents of the /etc/resolv.conf file. Which of the following commands would accomplish this task?

Options

  • Acat /etc/resolv.conf > /home/user/newfile
  • Becho /etc/resolv.conf > /home/user/newfile
  • Cgrep /etc/resolv.conf < /home/user/newfile
  • Dprintf /etc/resolv.conf > /home/user/newfile

Explanation

To create a new file with the exact contents of an existing file, the cat command can be used to display the source file's content, and the output redirection operator > will save that content to the destination file.

Common mistakes.

  • B. The echo command would simply print the literal string "/etc/resolv.conf" into /home/user/newfile, not the content of the file /etc/resolv.conf.
  • C. The grep command searches for patterns, and in this case, it attempts to search for the literal string "/etc/resolv.conf" within the contents of /home/user/newfile (due to input redirection <), which is not the intended operation.
  • D. The printf command would output the literal string "/etc/resolv.conf" into /home/user/newfile, similar to echo, rather than the content of the specified file.

Concept tested. File content redirection

Reference. https://man7.org/linux/man-pages/man1/cat.1.html

Topics

#File Management#Linux Commands#I/O Redirection#cat command

Community Discussion

No community discussion yet for this question.

Full XK0-005 PracticeBrowse All XK0-005 Questions