遞迴遍歷目錄的shell指令碼

2021-07-10 20:29:51 字數 999 閱讀 1546

#!/bin/sh

##晚上沒事,用shell寫了個遞迴遍歷目錄的指令碼,本指令碼實現遞迴遍歷指定目錄,列印目錄下的檔名(全路徑)。不為別的,就為了以後用著方便。

function scandir()

if [ $ = "/" ]

then

cur_dir=""

else

cur_dir=$(pwd)

fifor dirlist in $(ls $)

doif test -d $;then

cd $

scandir $/$

cd ..

else

#unix下時,你經常會看見每行檔案後面有個討 厭的^m 字元,有兩個簡單的方法可以取消它。 用"vi"開啟此檔案,在command mode下敲入: :%s/^v^m//g 或者,在unix shell下敲入: sed 's/^v^m//g' foo > foo.new

# sed 's/\r//g' pxa270_buzzer_drv.c >pxa270_buzzer_drv2.c

#    sed -i "s/^m//g" `grep "^m" -rl ./`

#            echo $/$

indent -npro -kr -i8 -ts8 -sob -l280 -ss -ncs -cp1 *.c *.h

fidone

}if test -d $1

then

scandir $1

elif test -f $1

then

echo "you input a file but not a directory,pls reinput and try again"

exit 1

else

echo "the directory isn't exist which you input,pls input a new one!!"

exit 1fi

0 給主人留下些什麼吧!~~

VBS指令碼遍歷目錄(遞迴呼叫)

set fso createobject scripting.filesystemobject set dc fso.drives for each d in dc if d.drivetype 1 or d.drivetype 2 then s d.driveletter scan s end i...

Shell遞迴遍歷目錄下檔案

遍歷linux某目錄下的所有檔案 bin bash 1是執行指令碼時,輸入的第乙個引數,這裡指的是使用者希望搜尋的目錄 下面的 是對目錄進行判斷,如果為空則使用指令碼所在的目錄 否則,搜尋使用者輸入的目錄 if z 1 d 1 then echo the directory is empty or ...

shell指令碼遞迴遍歷處理制定檔案

本例是乙個遍歷加密寒武紀模型的 主要注意幾個點 1 遞迴 參考 2 字串相等 3 字串取段 加密root目錄下的所有寒武紀模型,秘鑰 1234567890 bash encode.sh root 1234567890 bin bash function read dir echo now if no...