Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy only symbolic links through rsync

How do I copy symbolic links only (and not the file it points to) or other files using rsync?

I tried

rsync -uvrl input_dir output_dir

but I need to exclusively copy the symbolic links only ?

any trick using include exclude options?

like image 772
Newbiee Avatar asked Mar 19 '12 19:03

Newbiee


2 Answers

You can do it more easily like:

find /path/to/dir/ -type l -exec rsync -avP {} ssh_server:/path/to/server/ \;

EDIT: If you want to copy symbolic links of the current directory only without making it recursive. You can do:

find /path/to/dir/ -maxdepth 1 -type l -exec rsync -avP {} ssh_server:/path/to/server/ \;
like image 79
Rehmat Avatar answered Sep 28 '22 08:09

Rehmat


Per this question+answer, you can script this as a pipe. Pipes are an integral part of shell programming and shell scripting.

find /path/to/files -type l -print | \
  rsync -av --files-from=- /path/to/files user@targethost:/path

What's going on here?

The find command starts at /path/to/files and steps recursively through everything "under" that point. The options to find are conditions that limit what gets output by the -print option. In this case, only things of -type l (symbolic link, according to man find) will be printed to find's "standard output".

These files become the "standard input" of the rsync command's --file-from option.

Give it a shot. I haven't actually tested this, but it seems to me that it should work.

like image 23
ghoti Avatar answered Sep 28 '22 08:09

ghoti