开发者

Recursive follow files in bash

开发者 https://www.devze.com 2022-12-29 03:18 出处:网络
I have files which contain file names pointing to other files. These files contain further file names pointing further files and so on. I need a bash script which follows eac开发者_C百科h files recurs

I have files which contain file names pointing to other files. These files contain further file names pointing further files and so on. I need a bash script which follows eac开发者_C百科h files recursively and logs into file every touched file during the run.

file1:
   file2
   file3

file2:
   file4

file3:
   file5

file4 and file5 are empty. Result:

file1
file2
file4
file3
file5


Define

function scan() {
  echo $1
  local f
  while read f ; do
    scan $f
  done < $1
}

Use:

scan file1 > log

Update: accepted Dennis Williamson comment and replaced cat $1 | while ... done with the better performing while ... done < $1.

0

精彩评论

暂无评论...
验证码 换一张
取 消