Compare files on Linux - Here's how
The following practical tip shows you how to compare files under Linux.
How to compare files in Linux
First open the console with the key combination [Alt] + [Ctrl] + [T] or enter the term "Terminal" in the search bar. Use the cd command to navigate to the directory in which the texts are located. If you do not know where the files are stored, we will show you another practical tip on how to search for files under Linux.
- Linux only compares text files in the console - those looking for more specific applications will find what they are looking for in the software center.
- If you want to know where two files differ, enter "diff filename1 filename2". If the objects are the same, you will receive no output. If the two files differ, you will receive an error code such as "1c1". This tells you that the files in the first line differ.
- If you are not interested in the wrong lines and just want to know whether the files are the same or not, type in "diff -q filename1 filename2". Attention: The file extensions in the console are necessary for the diff command, otherwise you will receive an error message.
- The error code that appears when you omit the "-q" parameter consists of three units. The first number to the letter indicates the line of the first document in which the difference occurs. The middle letter is either an "a" for "append" if a letter is missing. The opposite is a "d" for "delete" if there is too much in the first file. A "c" says that two words are different and you should change the position. The last number stands for the corresponding line in the second file.
- If you want to compare three files, enter "diff3 filename1 filename2 filename3".
If you then no longer need one of the files, you will find another practical tip on how to delete files under Linux.