Linux command
sdiff 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Compare files side by side
sdiff [file1] [file2]
Interactive merge
sdiff -o [output] [file1] [file2]
Set output width
sdiff -w [120] [file1] [file2]
Suppress common lines
sdiff -s [file1] [file2]
Ignore case differences
sdiff -i [file1] [file2]
Ignore whitespace changes
sdiff -b [file1] [file2]
Ignore all whitespace
sdiff -W [file1] [file2]
Tab-expand output
sdiff -t [file1] [file2]
说明
sdiff compares two files side by side. It displays corresponding lines in parallel columns, marking differences with symbols. Output symbols indicate relationship: blank (identical), | (different), < (only in left), > (only in right). This visual format makes differences immediately apparent. Interactive merge mode (-o) creates a combined file from the two inputs. At each difference, you choose: left (l), right (r), edit left (el), edit right (er), or both (b). This enables manual resolution of differences. Width setting (-w) controls output columns. Narrow widths truncate lines; wider widths show more content. Terminal width is commonly used (e.g., -w 80 or -w $COLUMNS). Suppressing common lines (-s) shows only differences, useful for focusing on changes in files that are mostly identical. Whitespace and case options help compare files with formatting differences that aren't substantive.
参数
- -o _FILE_, --output _FILE_
- Interactive merge to output file.
- -w _NUM_, --width _NUM_
- Output width in columns.
- -s, --suppress-common-lines
- Don't show identical lines.
- -l, --left-column
- Show only left column for common lines.
- -b, --ignore-space-change
- Ignore changes in whitespace amount.
- -B, --ignore-blank-lines
- Ignore blank line changes.
- -i, --ignore-case
- Case-insensitive comparison.
- -W, --ignore-all-space
- Ignore all whitespace.
- -t, --expand-tabs
- Expand tabs to spaces.
- --strip-trailing-cr
- Strip trailing carriage returns.
- -a, --text
- Treat all files as text.
- -d, --minimal
- Find minimal set of changes.
- -H, --speed-large-files
- Heuristics for large files.
FAQ
What is the sdiff command used for?
sdiff compares two files side by side. It displays corresponding lines in parallel columns, marking differences with symbols. Output symbols indicate relationship: blank (identical), | (different), < (only in left), > (only in right). This visual format makes differences immediately apparent. Interactive merge mode (-o) creates a combined file from the two inputs. At each difference, you choose: left (l), right (r), edit left (el), edit right (er), or both (b). This enables manual resolution of differences. Width setting (-w) controls output columns. Narrow widths truncate lines; wider widths show more content. Terminal width is commonly used (e.g., -w 80 or -w $COLUMNS). Suppressing common lines (-s) shows only differences, useful for focusing on changes in files that are mostly identical. Whitespace and case options help compare files with formatting differences that aren't substantive.
How do I run a basic sdiff example?
Run `sdiff [file1] [file2]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -o _FILE_, --output _FILE_ do in sdiff?
Interactive merge to output file.