The correct answer is B. sed -i ' s/oldhostname/newhostname/ ' /etc/configuration.file because the sed (stream editor) command is specifically designed for searching, finding, and replacing text within files, which is exactly the requirement in this scenario. The -i option enables in-place editing, meaning the file is modified directly without needing to create a separate output file.
The substitution expression ' s/oldhostname/newhostname/ ' follows the standard sed syntax, where s stands for substitute. It replaces the first occurrence of oldhostname with newhostname on each line. This is a common and efficient method used by Linux administrators when performing configuration updates across files.
Option A is incorrect because cut is used for extracting sections of text, not replacing content, and piping into vi in this way is not valid for automated editing. Option C is incorrect because it filters lines containing oldhostname and redirects them to a file named newhostname, which does not perform any replacement and also overwrites data. Option D is incorrect because while awk can process text, the syntax shown does not correctly replace text within the file and does not write changes back to the original file.
In Linux+ objectives, mastering tools like sed is essential for automation and scripting tasks. Administrators frequently need to update configuration files programmatically, especially across multiple systems. Using sed ensures accuracy, efficiency, and scalability when performing such repetitive text modifications.
Submit