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.
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
echocommand would simply print the literal string "/etc/resolv.conf" into/home/user/newfile, not the content of the file/etc/resolv.conf. - C. The
grepcommand 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
printfcommand would output the literal string "/etc/resolv.conf" into/home/user/newfile, similar toecho, rather than the content of the specified file.
Concept tested. File content redirection
Topics
Community Discussion
No community discussion yet for this question.