CompTIA Linux+ (XK0-004) — Question 240
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?
Answer options
- A. cat /etc/resolv.conf > /home/user/newfile
- B. echo /etc/resolv.conf > /home/user/newfile
- C. grep /etc/resolv.conf < /home/user/newfile
- D. printf /etc/resolv.conf > /home/user/newfile
Correct answer: A
Explanation
The correct command is A because it uses 'cat' to read the contents of /etc/resolv.conf and redirect them into newfile. Option B simply echoes the filename instead of the file's content, C incorrectly uses 'grep' with the wrong syntax, and D uses 'printf' incorrectly as it does not output the file contents.