CompTIA Linux+ (XK0-005) — Question 308
A server’s IP address has been changed from 10.115.6.5 to 10.116.6.5. Because of this change, the application server needs to be reconfigured. Which of the following commands will allow the systems engineer to change the IP address in the /etc/app.cfg file quickly?
Answer options
- A. awk '{rep(/10.115.6.5/"10.116.6.5")}" /etc/app.cfg
- B. perl -i 's/10.115.6.5/10.116.6.5/g" /etc/app.cfg
- C. sed -i 's/10.115.6.5/10.116.6.5/g' /etc/app.cfg
- D. python -c “import sys;print file.replace('10.115.6.5','10.116.6.5')" < /etc/app.cfg
Correct answer: C
Explanation
The correct answer is C, as the 'sed' command is specifically designed for stream editing and can perform in-place substitutions directly within files. Options A and B have syntax errors, and option D incorrectly attempts to read the file and replace text using Python, which is not as efficient for this task.