mv files with | xargs

Solution 1:

You could try the -exec option with find command,

/etc/apache2/sites-enabled$ sudo find . -maxdepth 1 -type f -exec mv {} /etc/apache2/sites-available \;

For moving files owned by root, you need sudo permissions.

If you want to use xargs command then add -I option to it.

find . -maxdepth 1 -type f | sudo xargs -I {} mv {} /etc/apache2/sites-available/

Solution 2:

Ideally you should use -print0 with find, so filenames with spaces don't screw things up.

E.g. this should work :

find . -whatever-flags-go-here -print0 | xargs -r0 mv -t target-directory

mv -t is directly usable with xargs as the source files are at the end of the argument list:

   mv [OPTION]... -t DIRECTORY SOURCE...

   -t, --target-directory=DIRECTORY
          move all SOURCE arguments into DIRECTORY