What are the functions of the ‘diff’ command in Linux?
diff command is used to compare the differences between two files. In Linux, the diff command has the following functionalities:
- Compare two files and display the differences: The diff command can show the differences between two files by comparing their content, including additions, deletions, and modifications.
- Generate differential files: The diff command can be used to output the differences between files in text file format for easy processing and viewing.
- Recursively compare directories: Using the -r option of the diff command allows for comparing two directories and their subdirectories, displaying the differences.
- Ignore blank characters and blank lines: You can use the -b and -w options of the diff command to ignore white spaces and empty lines during the comparison process, focusing only on the actual differences.
- Compare binary files: The -b option of the diff command can be used to compare binary files and display the differences between the files.
- Create patch file: By using the -c option of the diff command, differences between files can be output in the form of a patch file, making it easier to apply the differences to other files.
- Merge files: By using the -m option of the diff command, you can combine the differences between two files into one file.
- Create a new file: By using the -a option of the diff command, you can copy the contents of one file to another file and mark any lines in the new file that do not exist as added content.