How to copy only symbolic links through rsync

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

I tried

rsync -uvrl input_dir output_dir

but do I only need to copy only symbolic links?

does any trick using include exclude options?

+6
source share
3 answers

Per this question + answer , you can script it like 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 runs in / path / to / files and recursively recursively goes through everything "under" this point. The find options are conditions that limit the output of results using the -print option. In this case, to search for "standard output", only -type l lines will be printed (symbolic link, according to man find ).

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

Take a picture. I have not actually tested this, but it seems to me that it should work.

+6
source

You can create a list of files, excluding links with find input_dir -not -type l , rsync has the option --exclude-from=exlude_file.txt

You can do this in two steps:

find input_dir -not -type l > /tmp/rsync-exclude.txt

rsync -uvrl --exclude-from=/tmp/rsync-exclude.txt input_dir output_dir

one line of bash:

rsync -urvl --exclude-from=<(find input_dir -not -type l | sed 's/^..//') input_dir output_dir

+4
source

You can make it easier:

 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 without making it recursive. You can do:

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

Source: https://habr.com/ru/post/911137/


All Articles