Error404
Error404

Reputation: 7131

xargs not functioning in linux

I am trying to use xargs for copying files after selecting them using this command

grep 'string' | awk '{print $2$3}' | xargs -I {} cp {} /dir1/dir2/dir3

I get the following error message per each file I am copying

cp: cannot stat `/dir1/dir2/dir3/file1.jpeg': No such file or directory

The problem that it is telling me the directory correctly, and telling me it is not found, the file1.jpeg is actually in the dir3 file and the whole route is 100% correct

I tried to use echo cp and I still get this message per file:

cp /dir1/dir2/dir3/file1.jpeg /new/directory/

Can anyone help? -Appreciated

Upvotes: 0

Views: 1183

Answers (1)

jaypal singh
jaypal singh

Reputation: 77135

You can remove grep and awk and use find along with xargs.

Something like this:

find /path/to/search/ -type f -iname "*string*" | xargs -0 cp -t /path/to/copy

You can also use exec option of find and avoid xargs.

Upvotes: 1

Related Questions