0
0
Linux CLIscripting~20 mins

diff for file comparison in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Diff Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of diff command with two similar files
Given two files 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?
ANo output
B
2c2
< banana
---
> banana
C
3c3
< cherry
---
> date
D
1a2
> banana
Attempts:
2 left
💡 Hint
Look for the line number where the files differ and how diff shows changes.
💻 Command Output
intermediate
2: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?
AOnly line numbers where files differ without content
BNo output if files differ
COutput in reverse order of lines
DUnified diff format showing context lines with '+' and '-' prefixes
Attempts:
2 left
💡 Hint
The -u option is often used for patches and shows more context.
💻 Command Output
advanced
2: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?
ALine by line text differences
BBinary files file1.bin and file2.bin differ
CSyntax error
DNo output
Attempts:
2 left
💡 Hint
diff handles binary files differently than text files.
🔧 Debug
advanced
2: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?
AThe files differ only in whitespace and diff is run with default options
BThe files are identical
CThe diff command is broken
DThe files have different names
Attempts:
2 left
💡 Hint
No output from diff means the files are identical.
🚀 Application
expert
3: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?
Adiff -ur dir1 dir2 > diff_report.txt
Bdiff -r dir1 dir2 | tee diff_report.txt
Cdiff -u dir1 dir2 > diff_report.txt
Ddiff dir1 dir2 > diff_report.txt
Attempts:
2 left
💡 Hint
You need recursive comparison with unified diff format.