

Three hyphens (“-“) represents the first file and three plus symbol (“+++”) represents second file, after two sign “-1,7” indicates the lines from 1st file and “+1,7” represents lines range from 2nd file. Use ‘-u’ option in diff command if you want to produce its output in unified format, example is illustrated below, ~]# diff -u aachen.txt sydney.txtĪbove output is somewhat similar to context format but unified format displays the output in concise way, here first two lines indicates the file names along with their modification date and time.

If any line which doesn’t require any change then it is prefixed by two spaces. Only single hyphen “-“ indicates that line needs to removed and plus symbol “+” indicates that line needs to added in the file. Example is shown below, ~]# diff -c aachen.txt sydney.txtįirst two lines represent file names along with their modification date and time and three asterisk symbol (“ ***“) indicates the first file and three hyphen symbol (“ -“) indicates the second file. Use ‘-c’ option in diff command to produce the diff command output in context format. Output of diff command “ 7d6” indicates that we need to delete 7th line in the first file to sync with the second file at line number 6. Let’s remove “Arch Linux” and “Fedora” from sydney.txt and then try to compare these files, Output of diff command “ 7a8” indicates that after the 7th line in the first file, we need to add another line to match 8th line of the second file. Let’s roll-back the above change and add a new line “ Arch Linux” in sydeny.txt at end of file and run the diff command again, In the output, 1c1 indicates that 1st line of the first file needs to be changed to make both the files identical. Now re-run the diff command, ~]# diff aachen.txt sydney.txt Let’s make some changes in aachen.txt, re-write open source as “ open-source”. Let’s compare the content of these files using diff command, ~]# diff aachen.txt sydney.txtĪbove output confirms that both the files are identical. Linux Rocks in the open source world, followings are the linux distributions: Let’s assume we have two files aachen.txt and sydney.txt and following is the content of these files, ~]# cat aachen.txt In this post, we will discuss diff command with practical examples. d -> it indicates some text has been deletedīy default, diff command displays the output in normal format, it means when contents of two files are identical then it will not produce any output but we will get the prompt.c -> it indicates that some text has been changed.a -> it indicates that something has been added.Output of diff command can be in following format:ĭifferent symbols of diff command output: Diff command plays an important in shell script where we want to run command based on the comparison of two files.
