Copy nested folders contents to one folder recursively (terminal)

前端 未结 3 1642
被撕碎了的回忆
被撕碎了的回忆 2021-01-30 11:23

I have a Wordpress upload folder that is structured using subfolders for months.

wolfr2:uploads wolfr$ tree .
.
|-- 2007
|   |-- 08
|   |   |-- beautifulkatamari         


        
相关标签:
3条回答
  • 2021-01-30 12:05

    Off the top of my head:

    find . -type f -name \*.jpg -exec cp \{\} $TARGETFOLDER \;
    

    If that doesn't work, comment and I'll try again, but find is definitely the way to go.

    0 讨论(0)
  • 2021-01-30 12:09

    None of the above commands worked for me as such on macOS 10.15. Here's the one that worked:

    find . -name "*.jpg" -exec cp /{/} [target folder path] \;
    
    0 讨论(0)
  • 2021-01-30 12:14

    This will copy all *.jpg files from the current folder to a new folder and preserve the directory structure.

    tar cvfp `find . -name "*.jpg"` | (cd <newfolder>; tar xfp -)
    

    To copy without preserving the directory structure:

    cp `find . -name "*.jpg"` <newfolder>
    
    0 讨论(0)
提交回复
热议问题