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

The name of the pictureThe name of the pictureThe name of the pictureClash 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?







share|improve this question




















  • 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














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?







share|improve this question




















  • 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












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?







share|improve this question












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?









share|improve this question











share|improve this question




share|improve this question










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
















  • 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










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





share|improve this answer




















  • 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










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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





share|improve this answer




















  • 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














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





share|improve this answer




















  • 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












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





share|improve this answer












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






share|improve this answer












share|improve this answer



share|improve this answer










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
















  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)