0

Can I copy *.png files without change subfolders address and name?

Example: Copy /photo to /pic converting /photo/2017/hello.png to /pic/2017/hello.png.

dessert
  • 39,982

2 Answers2

1

First create the directory you want to copy to:

mkdir -p pic/2017

Then copy over the files. Normally one would just need cp:

cp photo/2017/*.png pic/2017/

As you mentioned there are too many files and you probably receive an “Argument list too long” error, we’ll use printf and xargs to run cp as often as necessary:

printf "%s\0" photo/2017/*.png | xargs -0 cp -t pic/2017/

You can also use mcp from the mmv packageInstall mmv in the following way:

mcp -n "photo/2017/*.png" pic/2017/

-n let’s mcp only list the changes, remove it to actually perform the copying. Note the quoted asterisk: It’s not evaluated by the shell, but rather by mcp.

dessert
  • 39,982
0

What you want is to copy the directory recursively, so, you should do:

cp -a /photo /pic

This will copy all files and directories recursively and preserves file metadata.

If /photo has files that are not png files that you do not want to copy, you can do this after doing the above command:

find /pic -not -iname '*.png' -type f -print0 | xargs --no-run-if-empty -0 rm
double-beep
  • 195
  • 1
  • 4
  • 12
crass
  • 465