A system administrator needs to update a configuration file named app.conf. They must replace every instance of the old IP address 192.168.1.5 with the new IP address 10.10.0.5 within the file. The changes need to be saved directly back into app.conf. Which of the following commands will accomplish this task correctly?
sed -i 's/192.168.1.5/10.10.0.5/' app.conf
sed 's/192.168.1.5/10.10.0.5/g' app.conf > app.conf
The correct command is sed -i 's/192.168.1.5/10.10.0.5/g' app.conf. Here is a breakdown of the command:
sed is the stream editor command.
The -i option stands for "in-place" and modifies the file directly.
's/old/new/g' is the substitution command.
s indicates the substitute command.
/192.168.1.5/ is the pattern to search for.
/10.10.0.5/ is the replacement string.
g is the global flag, which ensures all occurrences on each line are replaced, not just the first one. The command sed 's/192.168.1.5/10.10.0.5/g' app.conf is incorrect because it lacks the -i flag; it will only print the modified text to standard output and will not save the changes to the file. The command sed 's/192.168.1.5/10.10.0.5/g' app.conf > app.conf is incorrect and dangerous. The shell processes the redirection > by truncating the output file (app.conf) before the sed command runs. This results in sed reading an empty file and the original content being lost. The command sed -i 's/192.168.1.5/10.10.0.5/' app.conf is incorrect because it is missing the global g flag. It would only replace the first occurrence of the IP address on any given line.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is the purpose of the `-i` flag in the `sed` command?
Open an interactive chat with Bash
What does the `g` flag do in the `sed` command?
Open an interactive chat with Bash
Why is `sed 's/old/new/g' file > file` a dangerous command?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
System Management
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99
$19.99/mo
Billed monthly, Cancel any time.
3 Month Pass
$44.99
$14.99/mo
One time purchase of $44.99, Does not auto-renew.
MOST POPULAR
Annual Pass
$119.99
$9.99/mo
One time purchase of $119.99, Does not auto-renew.
BEST DEAL
Lifetime Pass
$189.99
One time purchase, Good for life.
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .