Unix shell file copy flattening folder structure

后端 未结 5 1406
走了就别回头了
走了就别回头了 2021-01-30 08:52

On the UNIX bash shell (specifically Mac OS X Leopard) what would be the simplest way to copy every file having a specific extension from a folder hierarchy (including subdirect

5条回答
  •  遇见更好的自我
    2021-01-30 09:35

    The only problem with Magnus' solution is that it forks off a new "cp" process for every file, which is not terribly efficient especially if there is a large number of files.

    On Linux (or other systems with GNU coreutils) you can do:

    find . -name "*.xml" -print0 | xargs -0 echo cp -t a
    

    (The -0 allows it to work when your filenames have weird characters -- like spaces -- in them.)

    Unfortunately I think Macs come with BSD-style tools. Anyone know a "standard" equivalent to the "-t" switch?

提交回复
热议问题