Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


sending incremental file list







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.

share|improve this question
up vote 1 down vote accepted

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@: @/@'
share|improve this answer
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 Mar 14 '13 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.

share|improve this answer
Hi terdon, Thanks for the input. This worked and gave me the absolute path. – KumarJohn Mar 14 '13 at 6:11
@user2119462 you're welcome. If one of the answers here helped you, please accept and/or upvote it. – terdon Mar 14 '13 at 12:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .