Is it possible to âcloneâ with rsync a folder to another by creating only symbolic links

Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
Is it possible to use rsync to "clone" a folder to a new folder but create the new folder tree structure as a symbolic link to the SOURCE.
cp -as SOURCE DEST
-s, --symbolic-link
make symbolic links instead of copying
The above command do the trick but it will not remove files that added manually to DEST if i run the cp command again. that why i thought of using using rsync.
any suggestion on how to achieve that?
rsync cp
add a comment |Â
up vote
2
down vote
favorite
Is it possible to use rsync to "clone" a folder to a new folder but create the new folder tree structure as a symbolic link to the SOURCE.
cp -as SOURCE DEST
-s, --symbolic-link
make symbolic links instead of copying
The above command do the trick but it will not remove files that added manually to DEST if i run the cp command again. that why i thought of using using rsync.
any suggestion on how to achieve that?
rsync cp
Some shell script that lists files on origin and destination, removes duplicates from the list and then erase the extra files from disk?
â Zip
Oct 22 '17 at 16:48
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Is it possible to use rsync to "clone" a folder to a new folder but create the new folder tree structure as a symbolic link to the SOURCE.
cp -as SOURCE DEST
-s, --symbolic-link
make symbolic links instead of copying
The above command do the trick but it will not remove files that added manually to DEST if i run the cp command again. that why i thought of using using rsync.
any suggestion on how to achieve that?
rsync cp
Is it possible to use rsync to "clone" a folder to a new folder but create the new folder tree structure as a symbolic link to the SOURCE.
cp -as SOURCE DEST
-s, --symbolic-link
make symbolic links instead of copying
The above command do the trick but it will not remove files that added manually to DEST if i run the cp command again. that why i thought of using using rsync.
any suggestion on how to achieve that?
rsync cp
asked Oct 22 '17 at 16:41
Asaf Magen
249313
249313
Some shell script that lists files on origin and destination, removes duplicates from the list and then erase the extra files from disk?
â Zip
Oct 22 '17 at 16:48
add a comment |Â
Some shell script that lists files on origin and destination, removes duplicates from the list and then erase the extra files from disk?
â Zip
Oct 22 '17 at 16:48
Some shell script that lists files on origin and destination, removes duplicates from the list and then erase the extra files from disk?
â Zip
Oct 22 '17 at 16:48
Some shell script that lists files on origin and destination, removes duplicates from the list and then erase the extra files from disk?
â Zip
Oct 22 '17 at 16:48
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
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
i â«appreciate your well written answer . do you think using hard link will be better?
â Asaf Magen
Oct 22 '17 at 20:59
@AsafMagen "Better"? The only case where it will not work is when the source and destination directories are on two different filesystems (partitions). I can say nothing about whether it would be "better".
â Kusalananda
Oct 22 '17 at 21:20
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
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
i â«appreciate your well written answer . do you think using hard link will be better?
â Asaf Magen
Oct 22 '17 at 20:59
@AsafMagen "Better"? The only case where it will not work is when the source and destination directories are on two different filesystems (partitions). I can say nothing about whether it would be "better".
â Kusalananda
Oct 22 '17 at 21:20
add a comment |Â
up vote
3
down vote
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
i â«appreciate your well written answer . do you think using hard link will be better?
â Asaf Magen
Oct 22 '17 at 20:59
@AsafMagen "Better"? The only case where it will not work is when the source and destination directories are on two different filesystems (partitions). I can say nothing about whether it would be "better".
â Kusalananda
Oct 22 '17 at 21:20
add a comment |Â
up vote
3
down vote
up vote
3
down vote
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
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
answered Oct 22 '17 at 17:04
Kusalananda
105k14209326
105k14209326
i â«appreciate your well written answer . do you think using hard link will be better?
â Asaf Magen
Oct 22 '17 at 20:59
@AsafMagen "Better"? The only case where it will not work is when the source and destination directories are on two different filesystems (partitions). I can say nothing about whether it would be "better".
â Kusalananda
Oct 22 '17 at 21:20
add a comment |Â
i â«appreciate your well written answer . do you think using hard link will be better?
â Asaf Magen
Oct 22 '17 at 20:59
@AsafMagen "Better"? The only case where it will not work is when the source and destination directories are on two different filesystems (partitions). I can say nothing about whether it would be "better".
â Kusalananda
Oct 22 '17 at 21:20
i â«appreciate your well written answer . do you think using hard link will be better?
â Asaf Magen
Oct 22 '17 at 20:59
i â«appreciate your well written answer . do you think using hard link will be better?
â Asaf Magen
Oct 22 '17 at 20:59
@AsafMagen "Better"? The only case where it will not work is when the source and destination directories are on two different filesystems (partitions). I can say nothing about whether it would be "better".
â Kusalananda
Oct 22 '17 at 21:20
@AsafMagen "Better"? The only case where it will not work is when the source and destination directories are on two different filesystems (partitions). I can say nothing about whether it would be "better".
â Kusalananda
Oct 22 '17 at 21:20
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f399748%2fis-it-possible-to-clone-with-rsync-a-folder-to-another-by-creating-only-symbol%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Some shell script that lists files on origin and destination, removes duplicates from the list and then erase the extra files from disk?
â Zip
Oct 22 '17 at 16:48