Linux command
diff 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Compare
diff [file1.txt] [file2.txt]
Unified
diff -u [file1.txt] [file2.txt]
Compare
diff -r [dir1] [dir2]
Side-by-side
diff -y [file1.txt] [file2.txt]
Ignore
diff -w [file1.txt] [file2.txt]
说明
diff compares files line by line and outputs the differences. It's essential for version control, code review, and understanding changes between file versions. The tool forms the basis of patch files and is used by version control systems.
参数
- -u, --unified
- Unified diff format (recommended)
- -c, --context
- Context diff format
- -y, --side-by-side
- Side-by-side comparison
- -r, --recursive
- Recursively compare directories
- -q, --brief
- Report only if files differ
- -s, --report-identical-files
- Report when files are identical
- -w, --ignore-all-space
- Ignore whitespace changes
- -b, --ignore-space-change
- Ignore whitespace amount changes
- -B, --ignore-blank-lines
- Ignore blank line changes
- -i, --ignore-case
- Case-insensitive comparison
- -N, --new-file
- Treat missing files as empty
FAQ
What is the diff command used for?
diff compares files line by line and outputs the differences. It's essential for version control, code review, and understanding changes between file versions. The tool forms the basis of patch files and is used by version control systems.
How do I run a basic diff example?
Run `diff [file1.txt] [file2.txt]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -u, --unified do in diff?
Unified diff format (recommended)