Challenge - 5 Problems
Diff Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Output of diff command with two similar files
Given two files
file1.txt:
apple
banana
cherry
file2.txt:
apple
banana
date
What is the output of the command
file1.txt and file2.txt with the following contents:file1.txt:
apple
banana
cherry
file2.txt:
apple
banana
date
What is the output of the command
diff file1.txt file2.txt?Attempts:
2 left
💡 Hint
Look for the line number where the files differ and how diff shows changes.
✗ Incorrect
The diff command shows that line 3 differs: 'cherry' in file1.txt is replaced by 'date' in file2.txt. The output format is 'c' followed by the differing lines.
💻 Command Output
intermediate2:00remaining
Using diff with -u option
What is the main difference in output when running
diff -u file1.txt file2.txt compared to diff file1.txt file2.txt for two files with small differences?Attempts:
2 left
💡 Hint
The -u option is often used for patches and shows more context.
✗ Incorrect
The -u option produces a unified diff format that shows lines before and after the change with '+' for additions and '-' for deletions, making it easier to understand changes.
💻 Command Output
advanced2:00remaining
Output of diff with binary files
What output does the command
diff file1.bin file2.bin produce if both files are binary and differ?Attempts:
2 left
💡 Hint
diff handles binary files differently than text files.
✗ Incorrect
When diff detects binary files that differ, it outputs a simple message stating the files differ without showing line differences.
🔧 Debug
advanced2:00remaining
Why does diff show no output for two different files?
You run
diff fileA.txt fileB.txt but see no output, even though you know the files differ. Which of the following is the most likely reason?Attempts:
2 left
💡 Hint
No output from diff means the files are identical.
✗ Incorrect
diff produces no output when the two files are identical. However, if the files differ only in whitespace and diff is run with default options, it may also produce no output.
🚀 Application
expert3:00remaining
Automate file difference report generation
You want to create a script that compares two directories
dir1 and dir2 recursively and outputs a unified diff for each differing file into a single report file diff_report.txt. Which command pipeline best achieves this?Attempts:
2 left
💡 Hint
You need recursive comparison with unified diff format.
✗ Incorrect
The -r option makes diff recursive, and -u produces unified diff format. Redirecting output to a file saves the report.