Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there a way to get rsync to print the full filepaths to all files that are different without actually transferring any files?

Alternatively, I need a way to diff the files across two trees (over SSH) based only on change in size or last-modified time.

Thanks.

share|improve this question

2 Answers 2

Rsync has a dry-run option:

-n, --dry-run show what would have been transferred

I am not sure if this is what you want.

If you want to diff the files across two trees, you could maybe recursively search the two directions with find and pipe to output to ls and pipe both to a file. You could then use diff to compare the files.

share|improve this answer
1  
+1, this is built in to rsync. The detail of the output of --dry-run will depend on your use of the -v and --progress options - so if you get no output at all check these options are set as needed. I've noticed that it will send directory names even when files have not changed, but you can filter these out by passing the output through sed or similar. –  David Spillett Apr 2 '13 at 16:55

I would go for something like this:

#! /bin/bash 

set -eu   ## Stop on errors and on undefined variables

## The local directory name
LOCAL_DIR=$1
## The remote directory in rsync sintax. Example: "machine:directory"
REMOTE_DIR=$2

shift 
shift 
# Now the first two args are gone and any other remaining arguments, if any, 
# can be expanded with $* or $@

# Create temporary file in THIS directory (hopefully in the same disk as $1:
# we need to hard link, which can only made in the same partition)
tmpd="$(mktemp -d  "$PWD/XXXXXXX.tmp" )"

# Upon exit, remove temporary directory, both on error and on success
trap 'rm -rf "$tmpd"' EXIT

# Make a *hard-linked* copy of our repository. It uses very little space 
# and is very quick 
cp -al "$LOCAL_DIR" "$tmpd"

# Copy the files. The final «"$@"» allows us to pass on arguments for rsync 
# from the command line (after the two directories).
rsync -a "$REMOTE_DIR"/   "$tmpd/"  --size-only "$@"

# Compare both trees
meld "$LOCAL_DIR"  "$tmpd"

For example:

$ cd svn 
$ rsyncmeld myproject othermachine:myproject -v --exclude '*.svn' --exclude build
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.