I hope you enjoyed the article and feel free to leave a comment or feedback. We have seen how effective the diff command is in comparing two directories on a Linux OS environment. If you want the diff command to also report on identical files on all directory levels, our modified diff command implementation will look like the following: $ diff -qrs dir1 dir2 Comparing files and directories with the diff and comm Linux commands The Linux comm command makes it easy to compare files or the contents of directories with its columnar output. Modifying the diff command has provided a full comparative view of files and files within subdirectories of the directories we earlier created. For it to dig into these subdirectories, we need to include the command option -r for the diff command to be recursive. The command output above does not analyze the contents of the subdirectories we created. Comparing Two Directories in LinuxĪs per the above output, the diff command thoroughly analyzes the differences and commonalities in the two directories. Please note that we are implementing the diff command at the directory level hence no need to key in the absolute paths of dir1 and dir2. The command option -q reports on differing files within the directories. To implement the above command in favor of the two directories we just created, the final implementation of our diff command will look like the following: $ diff -q dir1 dir2 Therefore, in order to use it to compare two directories, we will modify the above syntax to resemble the following: $ diff -q /path/to/directory1 /path/to/directory2 This small file can then be used to either check/compare another folder hierarchy or be. The diff command comes pre-installed on all major Linux operating system distributions hence no need to consult your package manager about its existence.Īs specified in the above command syntax, the diff command is effective when comparing files in Linux. It generates a CRC32 for each file and stores it in one checksum file. The primary role diff command is to make a line-by-line comparison between two files and its usage syntax is as follows: $ diff. Once the installation process is complete, open the two file in Notepad++. The application will now close and install the plugin. Check on the Compare plugin and click on Install. It only shows you which files are different, not the internal differences. Click on Plugins and select Plugins Admin. Comparing Directories Using the diff Command This has the added bonus of being to easy to compare two directories on two different servers. We can now start looking at an effective way of comparing these two directories in a Linux operating system environment. The source directory will be mentioned with ReferenceObject and targeted will be with. Let us use the Linux tree command to view the final directory structures of these two directories we have created. Compare two directories using the Compare-Object command. These directories will contain some files and other sub-directories to make this article more interesting. We will name them dir1 and dir2 respectively. Let us create two directories with slightly similar directory structures which we will be referencing throughout this article.
0 Comments
Leave a Reply. |