rsync
would not create symbolic links but may create hard links for you:
$ ls -lR test-source
total 4
-rw-r--r-- 1 kk wheel 0 Oct 22 18:54 a
-rw-r--r-- 1 kk wheel 0 Oct 22 18:54 b
-rw-r--r-- 1 kk wheel 0 Oct 22 18:54 c
-rw-r--r-- 1 kk wheel 0 Oct 22 18:54 d
drwxr-xr-x 2 kk wheel 512 Oct 22 18:54 dir
test-source/dir:
total 0
-rw-r--r-- 1 kk wheel 0 Oct 22 18:54 e
-rw-r--r-- 1 kk wheel 0 Oct 22 18:54 f
-rw-r--r-- 1 kk wheel 0 Oct 22 18:54 g
-rw-r--r-- 1 kk wheel 0 Oct 22 18:54 h
Use the --link-dest
flag:
$ rsync -av --link-dest="$PWD/test-source" test-source/ test-destination/
sending incremental file list
created directory test-destination
sent 191 bytes received 52 bytes 486.00 bytes/sec
total size is 0 speedup is 0.00
The destination files are now hard-linked to the source directory (see the 2
in the second column of the ls -l
output):
$ ls -lR test-destination
total 4
-rw-r--r-- 2 kk wheel 0 Oct 22 18:54 a
-rw-r--r-- 2 kk wheel 0 Oct 22 18:54 b
-rw-r--r-- 2 kk wheel 0 Oct 22 18:54 c
-rw-r--r-- 2 kk wheel 0 Oct 22 18:54 d
drwxr-xr-x 2 kk wheel 512 Oct 22 18:54 dir
test-destination/dir:
total 0
-rw-r--r-- 2 kk wheel 0 Oct 22 18:54 e
-rw-r--r-- 2 kk wheel 0 Oct 22 18:54 f
-rw-r--r-- 2 kk wheel 0 Oct 22 18:54 g
-rw-r--r-- 2 kk wheel 0 Oct 22 18:54 h
The link count has also increased on the files in the source directory (obviously):
$ ls -lR test-source
total 4
-rw-r--r-- 2 kk wheel 0 Oct 22 18:54 a
-rw-r--r-- 2 kk wheel 0 Oct 22 18:54 b
-rw-r--r-- 2 kk wheel 0 Oct 22 18:54 c
-rw-r--r-- 2 kk wheel 0 Oct 22 18:54 d
drwxr-xr-x 2 kk wheel 512 Oct 22 18:54 dir
test-source/dir:
total 0
-rw-r--r-- 2 kk wheel 0 Oct 22 18:54 e
-rw-r--r-- 2 kk wheel 0 Oct 22 18:54 f
-rw-r--r-- 2 kk wheel 0 Oct 22 18:54 g
-rw-r--r-- 2 kk wheel 0 Oct 22 18:54 h
To remove files in the destination directory that does not exist in the source directory, use the --delete
flag:
$ touch test-destination/delete_me
$ rsync -av --delete --link-dest="$PWD/test-source" test-source/ test-destination/
sending incremental file list
deleting delete_me
./
sent 194 bytes received 29 bytes 446.00 bytes/sec
total size is 0 speedup is 0.00