0

I'm getting an error that I can't make heads or tails of when trying to use cp through xargs

grep -l -r .mp4 * | xargs cp -t ./Destination 

Results in

cp: invalid option -- 'G' 

The goal here is to search through the current folder, and copy all mp4 files to the folder Destination. I don't understand where the error message is getting the 'G' from though, as I'm not calling any option G, or even using the character G at all in the CP argument!

Can anyone help me understand what's going on here please? If it makes a difference i'm using the stock terminal window in a pretty fresh install of Ubuntu 18.04.3

7
  • Is there a file whose name starts with -G? Do you still get the error with [...] | xargs cp -t -- ./Destination? Commented Feb 7, 2020 at 16:07
  • Try doing xargs cp -t -- ./Destination Commented Feb 7, 2020 at 16:10
  • what if you substitute "xargs cp...." with "xargs echo"? Commented Feb 7, 2020 at 16:11
  • Thanks for the suggestions, sadly no dice.Using [...] | xargs cp -t -- ./Destination just gives me cp: failed to access '--': No such file or directory Also no, no file starts with -G Commented Feb 7, 2020 at 16:58
  • Xargs echo gives me a readout of the filenames. The only thing I can think of that seems potentially odd here is that the filenames all have spaces in them, could that be causing issues? Commented Feb 7, 2020 at 16:59

1 Answer 1

1

@steeldriver figured this out in the comments of the main question. The issue was being caused by whitespace in the filenames and modifying the command to grep -l -r -Z '.mp4' * | xargs -0 cp -t ./Test -- sorted it!

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.