UNIX tip – xargs with multiple commands

Xargs is an extremely powerful complement to the awesome find command. One downside is that you usually need to have a single pipeline. By default you can’t put together a bunch of commands which are not piped. However, it is possible to call a shell with xargs. In this way, you can execute multiple commands in this shell, but from xargs point of view, it is calling a single command – the shell interpreter. More details here:

bash – xargs with multiple commands as argument – Stack Overflow

Here is an example for copying some log files

find ../mca/logs -name '*20140713*' -type d | xargs -I XXX bash -c 'source=XXX; target=${source/foo/bar}; rsync -rltvu ${source}/ $target;'