Bash脚本在目录树中查找文件并将其附加到另一个文件
问题描述:
标题比我试图在脚本中表达的功能更加简化.
The title is rather more simplified than the functionality I am trying to express in a script.
我有一个一级的深层目录树(比示例大得多),其中包含各种内容,尽管我只感兴趣两个特定的文件.一个名为当前"的文件,另一个名为修订"的文件
I have a one-level deep directory tree (much bigger than example) which contain various content, although only two particular files are of interest to me. A file called 'current' and another called 'revisions'
- foo
|
|-> current
- bar
|
|-> current
|-> revisions
- baz
|
|-> not-affected
所考虑的脚本将从父目录触发到foo/bar/baz,并执行以下操作
The script in mind would be triggered from the parent directory to foo/bar/baz and it would perform the following
- 扫描所有子目录
-
找到包含当前"目录的目录时,它将
- Scan all subdirectories
When it finds a directory containing 'current' it will
- 将'current'的内容追加到修订版'cat $ {pwd}/current >> $ {pwd}/revisions'
答
如果深度为一级,这应该可以工作:
If it's one level deep, this should work:
for c in */current; do cat ${c} >> ${c%%current}revisions; done