1. 程式人生 > 其它 >shell指令碼編寫——遍歷資料夾下檔案

shell指令碼編寫——遍歷資料夾下檔案

技術標籤:Linux

注意:該指令碼只遍歷了指定目錄下的資料夾,非遍歷所有子節點

#! /bin/bash

demofun(){
    for file in `ls $1`
    do
        if test -f $file
        then
            echo "file:  $file"
        elif test -d $file
        then
            echo "path: $file"
			awk '{print FILENAME ":"} {print "\t"$0}'
$file/*.log > $file.log fi done } demofun ./