views:

48

answers:

1

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 each 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
A: 

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.

Chen Levy
Useless use of `cat`: `while ... done < $1`
Dennis Williamson
@Dennis Williamson, updated. Thanks.
Chen Levy