Copy all java files to specified folder

喜你入骨 提交于 2020-07-23 06:40:58

问题


I have a input path src and output path dest. src can have multiple sub-directories, which can again have further sub-directories and so on. I want to copy all java files (and directories that contain them) from src to dest "as-is". That is, if src was:

src - 
   f1.java
   f4.txt
   dir_1 - 
      f2.java
      dir_2 -
         f3.java 
   dir_3 - 
      f5.txt

dest should look like:

dest - 
   f1.java
   dir_1 - 
      f2.java
      dir_2 -
         f3.java 

I tried:

cp src/*.java dest

But it only copies f1.java, and nothing else. Can someone please help me out? (with solution/hints/links -- anything is good). I'm using ubuntu


回答1:


Just cd into /path/to/src, and run this:

find -type f -name '*.java' -exec cp --parents -t /path/to/dest {} +


来源:https://stackoverflow.com/questions/62232646/copy-all-java-files-to-specified-folder

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!