### Compare Configurations Ignoring Comments and Blank Lines Source: https://context7.com/distrotech/diffutils/llms.txt A practical example for comparing configuration files, ignoring blank lines and comment lines starting with '#' or ';'. ```bash diff -u -B -I '^\s*#' -I '^\s*;' config.old config.new ``` -------------------------------- ### Start Comparison from a Specific File Source: https://context7.com/distrotech/diffutils/llms.txt Use --starting-file to begin the directory comparison from a file that appears alphabetically after the specified one. ```bash diff -r --starting-file=middle_file.txt dir1/ dir2/ ``` -------------------------------- ### Practical Directory Comparison Excluding Logs and Temp Files Source: https://context7.com/distrotech/diffutils/llms.txt A practical example for comparing production and staging directories, excluding common temporary and log files, and version control directories. ```bash diff -rq \ --exclude='*.log' \ --exclude='*.tmp' \ --exclude='.git' \ --exclude='node_modules' \ production/ staging/ ``` -------------------------------- ### Combine Multiple Options for Code Comparison Source: https://context7.com/distrotech/diffutils/llms.txt A practical example combining whitespace and comment ignoring options for comparing Java code files. ```bash diff -u -b -B -w -I '^\s*//.*$' old.java new.java ``` -------------------------------- ### Generating and applying patches with diff and patch Source: https://context7.com/distrotech/diffutils/llms.txt Create unified or context diffs to generate patches, and apply them to source files or directories. ```bash diff -u original.c modified.c > changes.patch ``` ```bash diff -c original.c modified.c ``` ```bash diff -ruN original_project/ modified_project/ > project.patch ``` ```bash patch -p1 < changes.patch ``` ```bash patch -R -p1 < changes.patch ``` ```bash patch --dry-run -p1 < changes.patch ``` -------------------------------- ### Brief Recursive Comparison Source: https://context7.com/distrotech/diffutils/llms.txt The -rq option provides a brief recursive comparison, only reporting which files differ or are unique to one directory. ```bash diff -rq dir1/ dir2/ ``` -------------------------------- ### Create Patch with Custom Labels Source: https://context7.com/distrotech/diffutils/llms.txt Use the --label option to specify custom labels for the old and new files in the diff output. ```bash diff -u --label "Version 1.0" --label "Version 2.0" old.txt new.txt ``` -------------------------------- ### Compare Ignoring CVS/RCS Keyword Expansion Source: https://context7.com/distrotech/diffutils/llms.txt Use -I with patterns like '$Id:' or '$Revision:' to ignore differences caused by version control keyword expansion. ```bash diff -u -I '\$Id:' -I '\$Revision:' file1.c file2.c ``` -------------------------------- ### Report Identical Files Source: https://context7.com/distrotech/diffutils/llms.txt The -s option reports files that are identical in both directories, in addition to reporting differences. ```bash diff -rs dir1/ dir2/ ``` -------------------------------- ### Recursive Unified Diff for Patch Creation Source: https://context7.com/distrotech/diffutils/llms.txt Combine -r, -u, and -N for a recursive unified diff output suitable for creating patches that include new files. ```bash diff -ruN old_version/ new_version/ > upgrade.patch ``` -------------------------------- ### Custom Format Output with Line Group Formats Source: https://context7.com/distrotech/diffutils/llms.txt Utilize --old-group-format, --new-group-format, and --unchanged-group-format for fine-grained control over diff output. ```bash diff \ --old-group-format='DELETED:%<' \ --new-group-format='ADDED:%>' \ --unchanged-group-format='' \ file1.txt file2.txt ``` -------------------------------- ### Compare Two Files with diff Source: https://context7.com/distrotech/diffutils/llms.txt Use diff to compare files line-by-line, generate patches, or compare directory trees. Supports various output formats and filtering options. ```bash # Basic comparison of two files diff file1.txt file2.txt # Unified diff format (most common for patches, shows 3 lines of context) diff -u old_version.c new_version.c # Output: # --- old_version.c 2024-01-15 10:30:00.000000000 -0500 # +++ new_version.c 2024-01-15 11:45:00.000000000 -0500 # @@ -1,4 +1,5 @@ # #include # +#include # # int main() { # - printf("Hello"); # + printf("Hello World\n"); # Context diff format with 5 lines of context diff -c -C 5 original.py modified.py # Create a patch file for distribution diff -u original/ modified/ > changes.patch # Recursive directory comparison diff -r project_v1/ project_v2/ # Ignore whitespace changes diff -u -w file1.txt file2.txt # Ignore case differences diff -u -i file1.txt file2.txt # Brief output - only report if files differ diff -q file1.txt file2.txt # Output: Files file1.txt and file2.txt differ # Side-by-side comparison with 80 columns width diff -y -W 80 file1.txt file2.txt # Ignore blank lines and trailing whitespace diff -u -B -Z file1.txt file2.txt # Show C function context for each change diff -u -p source_old.c source_new.c # Exclude certain files when comparing directories diff -r --exclude='*.o' --exclude='.git' dir1/ dir2/ # Compare treating all files as text (useful for files with some binary content) diff -a file1.bin file2.bin # Generate ed script output diff -e old.txt new.txt > script.ed # RCS format output for revision control systems diff -n old.txt new.txt # Compare with minimal algorithm for best results (slower) diff -d file1.txt file2.txt ``` -------------------------------- ### Compare Three Files with diff3 Source: https://context7.com/distrotech/diffutils/llms.txt Use diff3 for three-way merges by comparing a version against a common ancestor and another version. ```bash # Basic three-way comparison diff3 my_version.txt original.txt their_version.txt ``` -------------------------------- ### Generate Output for TeX Documents Source: https://context7.com/distrotech/diffutils/llms.txt Format diff output for TeX documents using specific commands for old and new group formats. ```bash diff \ --old-group-format='\begin{em} %<\end{em} ' \ --new-group-format='\begin{bf} %>\end{bf} ' \ old.tex new.tex ``` -------------------------------- ### Unidirectional New File Comparison Source: https://context7.com/distrotech/diffutils/llms.txt The --unidirectional-new-file option treats absent files in the first directory as empty, useful for one-way synchronization. ```bash diff -r --unidirectional-new-file dir1/ dir2/ ``` -------------------------------- ### Compare Two Files Byte-by-Byte with cmp Source: https://context7.com/distrotech/diffutils/llms.txt Use cmp for binary file comparison or to find the exact byte position of differences. It is faster than diff for checking if files are identical. ```bash # Basic comparison - reports first difference cmp file1.bin file2.bin # Output: file1.bin file2.bin differ: byte 1045, line 12 # Silent mode - only use exit status (0=same, 1=different, 2=error) cmp -s file1.bin file2.bin echo $? # 0 if identical, 1 if different # Verbose mode - show all differing bytes cmp -l file1.bin file2.bin # Output: # 1045 101 142 # 1046 156 157 # 1047 144 167 # (byte_position octal_byte1 octal_byte2) # Show differing bytes with ASCII representation cmp -b file1.bin file2.bin # Output: file1.bin file2.bin differ: byte 1045, line 12 is 101 A 142 b # Skip initial bytes before comparing cmp -i 1024 file1.bin file2.bin # Skip different amounts in each file cmp -i 512:1024 file1.bin file2.bin # Skip 512 in file1, 1024 in file2 # Compare only first N bytes cmp -n 4096 file1.bin file2.bin # Compare with standard input cat file1.bin | cmp - file2.bin # Practical use: verify file copy integrity cp large_file.iso backup.iso cmp -s large_file.iso backup.iso && echo "Copy verified" || echo "Copy failed" # Compare two binary files with byte limit and skip cmp -i 100 -n 500 file1.bin file2.bin ``` -------------------------------- ### Recursive Directory Comparison Source: https://context7.com/distrotech/diffutils/llms.txt Use the -r option to recursively compare the contents of two directories. ```bash diff -r dir1/ dir2/ ``` -------------------------------- ### Exclude Files from a List Source: https://context7.com/distrotech/diffutils/llms.txt The -X option allows specifying a file containing a list of patterns to exclude from the directory comparison. ```bash echo -e "*.log\n*.tmp\n.git" > exclude_patterns.txt diff -r -X exclude_patterns.txt dir1/ dir2/ ``` -------------------------------- ### Side-by-side file merging with sdiff Source: https://context7.com/distrotech/diffutils/llms.txt Compare and merge files side-by-side. Interactive mode allows manual selection of changes for each conflict. ```bash sdiff file1.txt file2.txt ``` ```bash sdiff -w 160 file1.txt file2.txt ``` ```bash sdiff -s file1.txt file2.txt ``` ```bash sdiff -l file1.txt file2.txt ``` ```bash sdiff -o merged.txt file1.txt file2.txt ``` ```bash sdiff -o merged.txt -b -B file1.txt file2.txt ``` ```bash sdiff -i file1.txt file2.txt ``` ```bash sdiff -W file1.txt file2.txt ``` ```bash sdiff -t file1.txt file2.txt ``` ```bash sdiff -d file1.txt file2.txt ``` ```bash sdiff -o final_config.conf old_config.conf new_config.conf ``` ```bash sdiff -s -w 200 before.log after.log > differences.txt ``` -------------------------------- ### Treat Absent Files as Empty Source: https://context7.com/distrotech/diffutils/llms.txt The -N option treats files that exist in one directory but not the other as empty, useful for generating patches for new files. ```bash diff -rN dir1/ dir2/ ``` -------------------------------- ### Compare Directory to Single File Source: https://context7.com/distrotech/diffutils/llms.txt Compare a directory against a single file; diff will compare the file against all files with the same name within the directory. ```bash diff -r file.txt directory/ ``` -------------------------------- ### Generate C Preprocessor Merge Output Source: https://context7.com/distrotech/diffutils/llms.txt The -D option generates output suitable for C preprocessor directives, showing differences within conditional blocks. ```bash diff -D USE_NEW_VERSION old.c new.c > merged.c ``` -------------------------------- ### Multiple Ignore Patterns Source: https://context7.com/distrotech/diffutils/llms.txt Combine multiple -I options to ignore lines matching any of the specified regular expressions. ```bash diff -u -I '^//' -I '^#' -I '^\s*/\*' source1.c source2.c ``` -------------------------------- ### Ignore Blank Line Changes Source: https://context7.com/distrotech/diffutils/llms.txt Use the -B option to ignore changes that involve only the insertion or deletion of blank lines. ```bash diff -u -B file1.txt file2.txt ``` -------------------------------- ### Ignore Tab Expansion Source: https://context7.com/distrotech/diffutils/llms.txt The -E option treats tab characters as equivalent to spaces for comparison purposes. ```bash diff -u -E file1.txt file2.txt ``` -------------------------------- ### Ignore Case Differences Source: https://context7.com/distrotech/diffutils/llms.txt The -i option performs a case-insensitive comparison of file contents. ```bash diff -u -i file1.txt file2.txt ``` -------------------------------- ### Ignore Filename Case When Matching Files Source: https://context7.com/distrotech/diffutils/llms.txt Use --ignore-file-name-case to perform case-insensitive matching of filenames during directory comparison. ```bash diff -r --ignore-file-name-case Dir1/ Dir2/ ``` -------------------------------- ### Exclude Files Matching Pattern in Directory Comparison Source: https://context7.com/distrotech/diffutils/llms.txt Use the --exclude option to skip files or directories matching a specified pattern during recursive comparison. ```bash diff -r --exclude='*.pyc' --exclude='__pycache__' project1/ project2/ ``` -------------------------------- ### Three-way file merging with diff3 Source: https://context7.com/distrotech/diffutils/llms.txt Perform three-way merges between a base file and two modified versions. Use these commands to resolve conflicts or generate merge scripts. ```bash diff3 -e my.txt old.txt their.txt ``` ```bash diff3 -A my_version.txt base.txt their_version.txt ``` ```bash diff3 -m my_version.txt original.txt their_version.txt > merged.txt ``` ```bash diff3 -x my.txt old.txt their.txt ``` ```bash diff3 -3 my.txt old.txt their.txt ``` ```bash diff3 -E my.txt old.txt their.txt ``` ```bash diff3 -m --label="LOCAL" --label="BASE" --label="REMOTE" \ my_file.txt base_file.txt their_file.txt ``` ```bash diff3 -e -i my.txt old.txt their.txt | ed - my.txt ``` ```bash diff3 -m my_changes.txt version_1.0.txt their_changes.txt > merged_version.txt ``` ```bash diff3 -m my.txt old.txt their.txt > result.txt if [ $? -eq 1 ]; then echo "Conflicts detected - manual resolution required" grep -n "<<<<<<" result.txt fi ``` -------------------------------- ### Ignore All Whitespace Source: https://context7.com/distrotech/diffutils/llms.txt Use the -w option to ignore all whitespace characters when comparing lines. ```bash diff -u -w file1.txt file2.txt ``` -------------------------------- ### Ignore Changes in Amount of Whitespace Source: https://context7.com/distrotech/diffutils/llms.txt The -b option ignores changes in the amount of whitespace, treating multiple spaces or tabs as equivalent. ```bash diff -u -b file1.txt file2.txt ``` -------------------------------- ### Ignore Lines Matching a Regular Expression Source: https://context7.com/distrotech/diffutils/llms.txt Use the -I option with a regular expression to ignore lines that match the specified pattern. ```bash diff -u -I '^#.*' file1.txt file2.txt ``` ```bash diff -u -I '^\s*$' file1.txt file2.txt ``` ```bash diff -u -I 'TODO' file1.txt file2.txt ``` -------------------------------- ### Ignore Trailing Whitespace Source: https://context7.com/distrotech/diffutils/llms.txt Use the -Z option to ignore differences only in trailing whitespace characters. ```bash diff -u -Z file1.txt file2.txt ``` -------------------------------- ### Strip Trailing Carriage Returns Source: https://context7.com/distrotech/diffutils/llms.txt The --strip-trailing-cr option removes carriage return characters from the end of lines, useful for Windows/Unix compatibility. ```bash diff -u --strip-trailing-cr dos_file.txt unix_file.txt ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.