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
.
精彩评论