was trying to compare two directories. one directory is the reference directory(dir1) and the other is the directory where modifications(dir2) are being done
I need the list of files which are modified or added in the dir2 compared with dir1.
I used rsync and diff and getting the result. But need the files with absolute Path in the output.
diff --brief --recursive /test/dir2 /reference/dir1
Output is
Only in /test/dir2: king.txt
Only in /test/dir2/sdir2: abc.txt
Only in /test/dir2: test1
Only in /test/dir2/sdir3: test.txt
and using rsync
rsync -av --dry-run /test/dir2/ /reference/dir1
output
sending incremental file list
./
king.txt
test.txt
sdir2/
sdir2/abc.txt
test1/
sent 52712 bytes received 1339 bytes 108102.00 bytes/sec
total size is 0 speedup is 0.00 (DRY RUN)
need the list with the complete path /test/dir2/king.txt and to be stored in one file.
Best Regards, KJ.
2 Answers 2
Should be easy enough to tweak the diff output to match your needs ... just pipe the diff through sed.
sed -r -e 's/^.*Only in //' -e 's@: @/@'
-
Hi Tink, Thanks, this also gave the output with absolute path with extra "/" in the output if the command ends with "/" at the end of directory Output: > /test/dir2//king.txt If the command doesnot have any "/" at the end of directory the output was perfect.KumarJohn– KumarJohn2013年03月14日 06:13:50 +00:00Commented Mar 14, 2013 at 6:13
You could just parse the output of diff:
diff --brief --recursive /test/dir2/ /reference/dir1/ |
gawk '(/Only/){print 3ドル""$NF}' | sed 's/://'
Make sure you include the trailing / in the directory names, this solution expects them. Use /test/dir2/ and not /test/dir2. Also, this will not work if your file names contain spaces.
-
Hi terdon, Thanks for the input. This worked and gave me the absolute path.KumarJohn– KumarJohn2013年03月14日 06:11:24 +00:00Commented Mar 14, 2013 at 6:11
-
@user2119462 you're welcome. If one of the answers here helped you, please accept and/or upvote it.terdon– terdon2013年03月14日 12:16:26 +00:00Commented Mar 14, 2013 at 12:16