1

How can we copy file and/or directory only if on target the file exists and only if it is newer than on target, and for the directory case it must recursively copy with such capability
as

 $ ls -a ~/.config
 gtk-2.0/             
 gtk-3.0/
 SpeedCrunch/

$ ls -a /other/path/home/.config/ gtk-2.0/
gtk-3.0/ SpeedCrunch/

$ rsync -u --existing ~/.config /other/path/home/ skipping directory .

can't work.

What Linux utility and how to do/solve it ? Thank you before

1 Answers1

0

Quick:

You forgot to include the recursive switch "-r" :

rsync -u --existing -r ~/.config /other/path/home/

Extra Stuff:

Also, you may consider using -a switch which is equal to -rlptgoD to include recursive in addition to preserve some important attributes as follows:

  • -r: recurse into directories
  • -l: copy symlinks as symlinks
  • -p: preserve permissions
  • -t: preserve modification times
  • -g: preserve group
  • -o: preserve owner (super-user only)
  • -D: preserve special files same as --devices --specials

Use follows for testing:

mkdir src
touch src/file{1..3}
touch src/thefile
# Destination:
mkdir dst
touch dst/file{1..3}
touch -d 20201023 dst/thefile
# List all
free -D src dst

Try now:

rsync -rt -uPv --existing src dst/

I used:

  • -r: recurse into directories
  • -t: preserve modification times
  • -u: skip files that are newer on the receiver
  • -P: show progress during transfer
  • -v: increase verbosity
  • --existing: skip creating new files on receiver