How to pipe the results of 'find' to mv in Linux
xargs
is commonly used for this, and mv
on Linux has a -t
option to facilitate that.
find ./ -name '*article*' | xargs mv -t ../backup
If your find
supports -exec ... \+
you could equivalently do
find ./ -name '*article*' -exec mv -t ../backup {} \+
The -t
option is a GNU extension, so it is not portable to systems which do not have GNU coreutils
(though every proper Linux I have seen has that, with the possible exception of Busybox). For complete POSIX portability, it's of course possible to roll your own replacement, maybe something like
find ./ -name '*article*' -exec sh -c 'mv "$@" "$0"' ../backup {} \+
where we shamelessly abuse the convenient fact that the first argument after sh -c 'commands'
ends up as the "script name" parameter in $0
so that we don't even need to shift
it.
Probably see also https://mywiki.wooledge.org/BashFAQ/020
find ./ -name '*article*' -exec mv {} ../backup \;
OR
find ./ -name '*article*' | xargs -I '{}' mv {} ../backup