2

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.

asked Mar 13, 2013 at 18:57

2 Answers 2

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@: @/@'
answered Mar 13, 2013 at 19:13
1
  • 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. Commented Mar 14, 2013 at 6:13
3

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.

answered Mar 13, 2013 at 19:14
2
  • Hi terdon, Thanks for the input. This worked and gave me the absolute path. Commented Mar 14, 2013 at 6:11
  • @user2119462 you're welcome. If one of the answers here helped you, please accept and/or upvote it. Commented Mar 14, 2013 at 12:16

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.