Bird
0
0

What will be the output of diff -u fileA.txt fileB.txt if fileA.txt contains:

medium📝 Command Output Q5 of 15
Linux CLI - Viewing and Editing Files
What will be the output of diff -u fileA.txt fileB.txt if fileA.txt contains:
line1
line2
line3
and fileB.txt contains:
line1
lineX
line3
?
Aline2 replaced by lineX
B@@ -1,3 +1,3 @@\n line1\n-line2\n+lineX\n line3
CNo differences found
D2c2\n< line2\n---\n> lineX
Step-by-Step Solution
Solution:
  1. Step 1: Understand unified diff (-u) output

    The -u option shows context lines with '@@' and marks removed lines with '-' and added lines with '+'.
  2. Step 2: Compare the files line by line

    Only line 2 differs: 'line2' vs 'lineX'. The output shows this with context lines.
  3. Final Answer:

    @@ -1,3 +1,3 @@ line1 -line2 +lineX line3 -> Option B
  4. Quick Check:

    diff -u shows unified diff with context and line changes [OK]
Quick Trick: Use -u for unified diff showing context lines [OK]
Common Mistakes:
  • Expecting simple diff output with -u
  • Ignoring context lines
  • Misreading diff symbols

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes