0
shuf -zn1 -e *.jpg | xargs -0 cp -vt /home/myspace/
result i.e. Image00005.jpg

BUT, I want to rename the file at the same time i.e. Image00005.jpg to Image.jpg

Tried:

shuf -zn1 -e *.jpg | xargs -0 cp -vt /home/myspace/image.jpg
cp: failed to access '/home/twitter/image.jpg': No such file or directory

Any idea?

Yaron
  • 13,173

1 Answers1

2

Since the -t form of cp only accepts a target directory, you will need to use the traditional SOURCE TARGET form e.g.

shuf -zn1 -e *.jpg | xargs -0 -I{} cp -v {} /home/myspace/image.jpg
steeldriver
  • 136,215
  • 21
  • 243
  • 336
  • Thanks, but getting --- shuf -zn1 -e *.jpg | xargs -0 Image00002.jpg

    shuf -zn1 -e *.jpg | xargs -0 -I{} cp -v /home/myspace/image.jpg cp: missing destination file operand after '/home/myspace/image.jpg' Try 'cp --help' for more information.

    – Confluentes Info Aug 24 '17 at 10:45
  • Did you remember to include the {} in the cp command? – steeldriver Aug 24 '17 at 10:50