Sponsored Content
Top Forums Shell Programming and Scripting How to compare files in two folders using cmp? Post 302455894 by rubin on Wednesday 22nd of September 2010 04:32:33 PM
Old 09-22-2010
Quote:
Originally Posted by fuzzylogic25
...
1. Is CMP the right command to use to compare (verify identical data) of two files regardless of its type? eg video, document, executable, zip, encrypted file etc
Yes, 'cmp' does a byte by byte comparison of two files.

Quote:
Originally Posted by fuzzylogic25
2. How would you write a quick shell script to compare two folders?
One way would be ...
Code:
# Build first the lists to be compared:

	find /media/ntfsdrive/data/ /media/ext4drive/data/ -type f  |
               awk '/\/media\/ntfsdrive\/data\// { print > "list_1" }
                    /\/media\/ext4drive\/data\// { print > "list_2" }' 
	
# Do the actual comparison with 'cmp', ( assuming no whitespaces in the filenames ):

	 awk '{ getline s < "list_2"; print "cmp", $0, s }' list_1 | sh

Note that one list's filenames have to be in precise order with their counterparts in the other list, for 'cmp' to work correctly.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

CMP two files with slight difference and return code

I am comparing two files which are identical except for the timestamp which is incorporated within the otherwise same 372 bytes. I am using the command: cmp -s $Todays_file $Yesterdays_file -i 372 When I run the command without the -i 372 it shows the difference i.e. the timestamp.... (5 Replies)
Discussion started by: gugs
5 Replies

2. Shell Programming and Scripting

Compare 2 folders...

Hello, I try to compare 2 folders, i explain, i have file in this 2 folder and i want to print out the difference in this folders... ex: folder1: file1 file2 file3 folder2: file1 file2 print file3 I do a ls of the 2 folders and i use the command diff (diff $var1 $var2) without... (8 Replies)
Discussion started by: protocomm
8 Replies

3. Shell Programming and Scripting

Issue in comparing (cmp) two files

Hi All, I have to compare set of files so I created a case statement with the option to give more than one file to compare. The Problem now i am facing is, if I compare the files directly, from prompt or just using the script only for a particular file then It's saying No difference, but If I... (4 Replies)
Discussion started by: Sudhar
4 Replies

4. Shell Programming and Scripting

Compare the checksum of files in 2 different folders

Hi I have 2 different folders on different machines. they are supposed to be same but some time for unknown reason they are not. then we have to generate a report for files which are not matching. I was doing as below - cd folder1 find . -type f | sort | cksum >1.txt cd folder2 find .... (7 Replies)
Discussion started by: reldb
7 Replies

5. Shell Programming and Scripting

Compare files in two folders and delete missing ones

I do not know much about shell scripting so I am at a loss here. If someone can help me, that would be great! I have two directories /dir1 /dir2 I need to delete all files from /dir1 and that does not have a correspondent file in /dir2. It should NOT check file suffixes in /dir2 . Why?... (20 Replies)
Discussion started by: kaah
20 Replies

6. Shell Programming and Scripting

Compare 2 folders to find several missing files among huge amounts of files.

Hi, all: I've got two folders, say, "folder1" and "folder2". Under each, there are thousands of files. It's quite obvious that there are some files missing in each. I just would like to find them. I believe this can be done by "diff" command. However, if I change the above question a... (1 Reply)
Discussion started by: jiapei100
1 Replies

7. UNIX for Dummies Questions & Answers

Searching for folders/parent folders not files.

Hello again, A little while back I got help with creating a command to search all directories and sub directories for files from daystart of day x. I'm wondering if there is a command that I've overlooked that may be able to search for / write folder names to an output file which ideally... (2 Replies)
Discussion started by: Aussiemick
2 Replies

8. Shell Programming and Scripting

Linux Script to compare two folders and copy missing files

Hi, I need help in shell scripting. If someone can help me, that would be great! Problem. I want Linux Script to compare two folders and copy missing files. Description. I have two directories /dir1 /dir2 I need to copy all distinct/new/unique/missing files from /dir1 and that... (1 Reply)
Discussion started by: S.Praveen Kumar
1 Replies

9. Shell Programming and Scripting

How to copy files/folders and show the files/folders?

Hi, So i know we use cp -r as a basic to copy folders/files. I would like this BUT i would like to show the output of the files being copied. With the amazing knowledge i have i have gone as far as this: 1) find source/* -exec cp -r {} target/ \; 2) for ObjectToBeCopied in `find... (6 Replies)
Discussion started by: Imre
6 Replies

10. Shell Programming and Scripting

Script to compare files in 2 folders and delete the large file

Hello, my first thread here. I've been searching and fiddling around for about a week and I cannot find a solution.:confused: I have been converting all of my home videos to HEVC and sometimes the files end up smaller and sometimes they don't. I am currently comparing all the video files... (5 Replies)
Discussion started by: Josh52180
5 Replies
GZDIFF(1)						      General Commands Manual							 GZDIFF(1)

NAME
gzcmp, gzdiff - compare compressed files SYNOPSIS
gzcmp [ cmp_options ] file1 [ file2 ] gzdiff [ diff_options ] file1 [ file2 ] DESCRIPTION
gzcmp and gzdiff are used to invoke the cmp or the diff program on compressed files. All options specified are passed directly to cmp or diff. If only 1 file is specified, then the files compared are file1 and an uncompressed file1.gz. If two files are specified, then they are uncompressed if necessary and fed to cmp or diff. The exit status from cmp or diff is preserved. SEE ALSO
cmp(1), diff(1), gzmore(1), gzgrep(1), gznew(1), gzforce(1), gzip(1), gzexe(1) BUGS
Messages from the cmp or diff programs refer to temporary filenames instead of those specified. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +--------------------+-----------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +--------------------+-----------------+ |Availability | SUNWgzip | +--------------------+-----------------+ |Interface Stability | External | +--------------------+-----------------+ NOTES
Source for gzip is available in the SUNWgzipS package. GZDIFF(1)
All times are GMT -4. The time now is 06:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy