Comparing two files

Hello everyone

Can you please tell me how can I compare two files in Unix I know that I must use diff or cmp but it is for a specific use, I want to compare only the 10 first lines of those two files, thanks in advance.

Ps : I know it is a dumb and weird question :e.
 
What type of comparison are you wanting? You can use head to select the first 10 lines without too much trouble and then just compare the results between the two. Easiest way would be to take the results of that and just put them in temporary files to compare. But I do know that there are more sophisticated ways of doing it, if more complicated to actually do.
 
Thank you for you answer, I just want to compare but with a single command, I don't know if it is possible to mix diff or cmp with the head command, may someone give me the command to use, thanks in advance.
 
As hedwards said:

$ head -10 file1 > 10_lines_file1 && head -10 file2 > 10_lines_file2 && diff 10_lines_file1 10_lines_file2

After your comparison you might want to delete the temporary files using rm.
 
Back
Top