unix命令复制具有已修改目录结构的所有.h文件

unix命令复制具有已修改目录结构的所有.h文件

问题描述:

假设我有一个类似的文件夹结构:

Suppose I have a folder structure like:

图书馆\

  • UIToolkit \
    • 文件\
      • toolkit.h
      • toolkit.c
      • toolkit.resource
      • 文件\
        • network.h
        • network-info.txt

        ...

        我需要一个命令,以便我可以输入Libraries文件夹并指定一个Output文件夹,然后在Output文件夹中拥有:

        I need a command so that I can input the Libraries folder and specify a Output folder then in the Output folder I have:

        输出\

        • UIToolkit \
          • toolkit.h
          • network.h

          基本上是这样:

          1. 复制所有.h文件并保留文件夹结构
          2. 还将所有标题移到其子库的根文件夹中,无论它们在子库子文件夹中有多深.

          我正在使用rsync,但是它没有执行第二步,所以我想我需要进行一些快速而肮脏的修改吗?

          I was using rsync but it does not do 2nd step, so I guess I need some quick and dirty modification?

          非常感谢!

您可以说:

cd /path/to/Libraries
while read -r file; do
  odir=$(cut -d'/' -f2 <<< ${file});
  fname=$(basename ${file});
  cp "$file" "/path/to/Output/${odir}/${fname}";
done < <(find . -type f -name "*.h")

这将根据所需的目录结构将所有 *.h 文件复制到 Output 文件夹中.

This would copy all the *.h files to the Output folder as per the desired directory structure.