
- Kali Linux Tutorial
- Kali Linux - Home
- Installation & Configuration
- Information Gathering Tools
- Vulnerability Analyses Tools
- Kali Linux - Wireless Attacks
- Website Penetration Testing
- Kali Linux - Exploitation Tools
- Kali Linux - Forensics Tools
- Kali Linux - Social Engineering
- Kali Linux - Stressing Tools
- Kali Linux - Sniffing & Spoofing
- Kali Linux - Password Cracking Tools
- Kali Linux - Maintaining Access
- Kali Linux - Reverse Engineering
- Kali Linux - Reporting Tools
- Kali Linux Useful Resources
- Kali Linux - Quick Guide
- Kali Linux - Useful Resources
- Kali Linux - Discussion
Fastest way to tell if two files have the same contents in Unix/Linux
Let’s say that we have two files inside a directory called dir1, and at first both these files are different. Different in the sense that the text they contain isn’t the same.
The files in the folder −
immukul@192 dir1 % ls -ltr total 16 -rw-r--r-- 1 immukul staff 7 Jul 7 10:37 2.txt -rw-r--r-- 1 immukul staff 8 Jul 8 19:05 3.txt
The contents inside the first file(2.txt) looks something like this −
immukul@192 dir1 % cat 2.txt orange
The contents inside the second file(2.txt) looks something like this −
immukul@192 dir1 % cat 3.txt uorange
We can easily make use of the diff command to check if they have something different. Consider the command shown below −
diff 2.txt 3.txt
Output
1c1 < orange --- > uorange
But in case where the contents of the file are exactly the same, then the diff command won’t return any output.
In that case it is recommended to make use of the cmp command. The cmp command is a Linux utility command that is used to compare two files.
Command
cmp --silent 2.txt 3.txt || echo "Difference in Files"
Output
immukul@192 dir1 % cmp --silent 2.txt 3.txt || echo "Difference in Files" Difference in Files
- Related Articles
- Fastest Method to Check If Two Files Have Same Contents
- Fastest Way to multiply two Numbers
- How to Tell if a Mirror is Two Way or Not?
- How to search contents of multiple pdf files on Linux?
- An Easy Way to Hide Files and Directories in Linux
- How to Append Contents of Multiple Files Into One File on Linux?
- Splitting Files in Unix Systems
- How to Find Duplicate Files in Unix?
- How to know if two arrays have the same values in JavaScript?
- Simple way to find if two different lists contain exactly the same elements in Java
- The best way to compress and extract files using the tar command on linux
- How to swap two files in Linux command line?
- Check if two String objects have the same value in C#
- Fastest way to convert JavaScript NodeList to Array
- Fastest way to count number of rows in MySQL table?

Advertisements