1

I'm looking for a command that behaves both like

cp -al

in only creating hard links rather than copying file contents, and

rsync -a --delete

in removing files from the destination that are not present in the source. I've looked into rsync options related to hard links, but they don't seem able to only create hard links.

Does such a command exist on Linux?

  • 1
    Using rsync with --link-dest pointing to the source tree might do what you want. – wurtel Oct 29 '14 at 13:31
0

Let's say you are working with directories, named 'src' and 'dest', for the source and destination of your copy, respectively. You could use the following command pipe to eliminate destination files not present in the source:

find src/* dest/* |cut -d'/' -f2- |sort |uniq -u |xargs printf "dest/%s\n" |xargs rm -f

Beware that this only works if your file names don't contain whitespace or \'".

  • touch 'dest/ /home/user3443186' → there go all your files. Manipulating file names like this only works if you know that your file names don't contain any special characters. – Gilles Oct 29 '14 at 23:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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