濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > Shell腳本統(tǒng)計(jì)當(dāng)前目錄下目錄和文件的數(shù)量

Shell腳本統(tǒng)計(jì)當(dāng)前目錄下目錄和文件的數(shù)量

熱門標(biāo)簽:寧波智能外呼系統(tǒng)公司 聯(lián)通電話機(jī)器人怎么接 電銷機(jī)器人 劍魚 衛(wèi)星地圖標(biāo)注地名 奧維互動(dòng)地圖標(biāo)注參數(shù) 曲阜400電話辦理 申請(qǐng)公司400電話要注意什么 地圖標(biāo)注輻射圖案 安裝外呼系統(tǒng)費(fèi)用

Linux下如何統(tǒng)計(jì)當(dāng)前目錄下文件有多少個(gè),目錄又有多少個(gè)呢?

下面用shell寫一個(gè)腳本,放置在當(dāng)前目錄下,執(zhí)行即可。

復(fù)制代碼 代碼如下:
 
#!/bin/bash
 
#腳本名稱 dir
#定義一個(gè)函數(shù)fun_directory
 
fun_directory() {     
  let "filenum=0"
  let "dirnum=0"
 
for i in $( ls )
do
   if [ -d $i ]
   then
      let dirnum+=1
   else
      let filenum+=1
   fi
done
 
echo "The number of directorys is $dirnum"
echo "The number of files is $filenum"
 
}
 
#調(diào)用函數(shù)
 
fun_directory

我們測(cè)試一下:

復(fù)制代碼 代碼如下:

[root@localhost scripts]# pwd
/root/scripts
[root@localhost scripts]# ll |sort
drwxr-xr-x 2 root root 4096 06-12 10:44 charpter8
drwxr-xr-x 2 root root 4096 06-13 12:34 aaa
-rw-r--r-- 1 root root  105 06-13 08:56 file1
-rw-r--r-- 1 root root  106 06-12 14:24 8-9
-rw-r--r-- 1 root root  121 06-12 09:36 jiu
-rw-r--r-- 1 root root  133 06-13 11:09 temp
-rw-r--r-- 1 root root  210 06-12 13:40 8-8
-rw-r--r-- 1 root root  222 06-12 11:51 8-6
-rw-r--r-- 1 root root  247 06-12 11:35 8-5
-rw-r--r-- 1 root root  273 06-12 13:13 8-7
-rw-r--r-- 1 root root  292 06-12 10:57 8-1
-rw-r--r-- 1 root root  309 06-12 14:51 8-11
-rw-r--r-- 1 root root  314 06-12 15:01 8-17
-rw-r--r-- 1 root root  317 06-13 12:10 test
-rw-r--r-- 1 root root   51 06-12 11:00 8-2
-rw-r--r-- 1 root root   53 06-13 08:51 file
-rw-r--r-- 1 root root   67 06-13 10:17 10-4
-rw-r--r-- 1 root root   78 06-13 10:09 test.out
-rwxr-xr-x 1 root root  103 06-12 11:06 8-3
-rwxr-xr-x 1 root root  124 06-13 10:02 10-32
-rwxr-xr-x 1 root root  304 06-13 12:47 dir
-rwxr-xr-x 1 root root  316 06-12 11:21 8-4
#執(zhí)行腳本
[root@localhost scripts]# sh dir
The number of directorys is 2
The number of files is 20
[root@localhost scripts]#

可以看到,數(shù)據(jù)統(tǒng)計(jì)是準(zhǔn)確的。

您可能感興趣的文章:
  • 通過(guò)shell腳本循環(huán)進(jìn)入目錄執(zhí)行命令的方法
  • shell遞歸輸出文件名和目錄名的方法
  • shell獲取目錄下所有文件夾的名稱并輸出的實(shí)例
  • linux Shell獲取某目錄下所有文件夾的名稱
  • 獲取shell腳本自身所在目錄的Shell腳本分享
  • Shell腳本遍歷目錄并批量修改文件編碼
  • Linux中shell腳本獲取當(dāng)前工作目錄的方法

標(biāo)簽:安康 江西 大興安嶺 遵義 三門峽 上饒 仙桃 大慶

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Shell腳本統(tǒng)計(jì)當(dāng)前目錄下目錄和文件的數(shù)量》,本文關(guān)鍵詞  Shell,腳本,統(tǒng)計(jì),當(dāng)前,目,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Shell腳本統(tǒng)計(jì)當(dāng)前目錄下目錄和文件的數(shù)量》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于Shell腳本統(tǒng)計(jì)當(dāng)前目錄下目錄和文件的數(shù)量的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    资中县| 南陵县| 若羌县| 绥芬河市| 扎兰屯市| 大兴区| 西乌| 定西市| 扶沟县| 基隆市| 扎兰屯市| 临泽县| 东港市| 商丘市| 合阳县| 分宜县| 五峰| 集贤县| 泗阳县| 彭泽县| 界首市| 青河县| 广元市| 陆河县| 随州市| 从江县| 布拖县| 贵港市| 阳信县| 民县| 巨鹿县| 定西市| 泰安市| 汉沽区| 喀什市| 醴陵市| 邮箱| 垦利县| 余江县| 伊川县| 浦北县|