Bash脚本在目录树中查找文件并将其附加到另一个文件 [英] Bash script to find a file in directory tree and append it to another file

查看:38
本文介绍了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

  1. 扫描所有子目录
  2. 找到包含当前"目录的目录时,它将

  1. Scan all subdirectories
  2. When it finds a directory containing 'current' it will

  1. 将'current'的内容追加到修订版'cat $ {pwd}/current >> $ {pwd}/revisions'

  • 不包含名为"current"的文件的目录将不受影响
  • 推荐答案

    如果深度为一级,这应该可以工作:

    If it's one level deep, this should work:

    for c in */current; do cat ${c} >> ${c%%current}revisions; done
    

    这篇关于Bash脚本在目录树中查找文件并将其附加到另一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆