文件個數腳本
發布時間: 2023-07-18 08:11:36
1. 如何用shell腳本統計出當前目錄下子目錄,還有所有可讀,可寫,可執行的文件的個數
#!/bin/bash
fcnt=0
dcnt=0
frcnt=0
fwcnt=0
fxcnt=0
forfilein*
do
if[-f$file];then
letfcnt+=1
if[-r$file];then
letfrcnt+=1
fi
if[-w$file];then
letfwcnt+=1
fi
if[-x$file];then
letfxcnt+=1
fi
elif[-d$file];then
letdcnt+=1
fi
done
echo"Thereare$fcntfilesin$PWD"
echo-e" Thereare$frcntreadablefilesin$PWD"
echo-e" Thereare$fwcntwriteablefilesin$PWD"
echo-e" Thereare$fxcntexecuteablefilesin$PWD"
echo"Thereare$dcntdirectoriesin$PWD"
2. 怎麼用bat腳本創建一個txt文件,內容為指定個數的「FF」
@echooff
rem輸出指定數量的字元串到txt文件
set#=Anyquestion&set$=Q&set/az=0x53b7e0b4
title%#%+%$%%$%%z%
cd/d"%~dp0"
set"keyword=FF"
set"count=100"
set"txtfile=xxx.txt"
powershell-NoProfile-ExecutionPolicybypass"$s='%keyword%'*%count%;[IO.File]::WriteAllText('%txtfile%',$s,[Text.Encoding]::Default);"
echo;%#%+%$%%$%%z%
pause
3. shell腳本實現統計目錄下(包括子目錄)所有文件的個數
在shell終端中輸入下列命令:
#在當前目錄生成腳本文件countfile
cat>countfile<<SCRIPT
#!/bin/sh
find"$@"-typef|
wc-l
SCRIPT
#為腳本添加許可權
chmod+xcountfile
#執行用例
./countfile~
4. 跪求 用Shell 腳本 實現 統計test目錄的各文件的行數 並分類
#!/bin/bash
# count the line of the file.
MYDIR="/root/test"
DIRLIST=`ls ${MYDIR}`
SF=()
MF=()
LF=()
for i in ${DIRLIST}
do
LINE=`cat ${MYDIR}/$i | wc -l`
if ((${LINE}<10))
then
SF=(${SF[*]} $i)
elif ((${LINE}>=10)) && ((${LINE}<=100))
then
MF=(${MF[*]} $i)
elif ((${LINE}>100))
then
LF=(${LF[*]} $i)
fi
done
echo Small files: ${SF[*]}
echo Medium files: ${MF[*]}
echo Large files: ${LF[*]}
已測試正確並無錯誤,把你要測試的目錄的路徑改下即可
熱點內容