欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2014年12月22日 09:18:57   投稿:junjie  
這篇文章主要介紹了Shell腳本統(tǒng)計(jì)當(dāng)前目錄下目錄和文件的數(shù)量,Linux下如何統(tǒng)計(jì)當(dāng)前目錄下文件有多少個(gè),目錄又有多少個(gè)呢,使用本文腳本即可實(shí)現(xiàn),需要的朋友可以參考下

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

下面用shell寫(xiě)一個(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ān)文章

  • 阿里云主機(jī)一鍵安裝lamp、lnmp環(huán)境的shell腳本分享

    阿里云主機(jī)一鍵安裝lamp、lnmp環(huán)境的shell腳本分享

    這篇文章主要介紹了阿里云主機(jī)一鍵安裝lamp、lnmp環(huán)境的shell腳本分享,需要的朋友可以參考下
    2014-07-07
  • Linux中sftp常用命令整理

    Linux中sftp常用命令整理

    sftp命令是一款交互式的文件傳輸程序,不僅對(duì)傳輸?shù)乃行畔⑹褂胹sh加密,它還支持公鑰認(rèn)證和壓縮等功能。這篇文章整理了Linux中sftp的常用命令,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-06-06
  • Linux截取某一段時(shí)間的日志問(wèn)題

    Linux截取某一段時(shí)間的日志問(wèn)題

    這篇文章主要介紹了Linux截取某一段時(shí)間的日志問(wèn)題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-01-01
  • Linux Shell函數(shù)返回值

    Linux Shell函數(shù)返回值

    這篇文章主要介紹了Linux Shell函數(shù)返回值,需要的朋友可以參考下
    2016-11-11
  • shell腳本編程之if語(yǔ)句學(xué)習(xí)筆記

    shell腳本編程之if語(yǔ)句學(xué)習(xí)筆記

    這篇文章主要介紹了shell腳本編程之if語(yǔ)句學(xué)習(xí)筆記,本文先是給出了程序代碼,然后詳細(xì)的分解了第句代碼的作用,需要的朋友可以參考下
    2014-09-09
  • 一天一個(gè)shell命令 linux文本系列-file命令用法

    一天一個(gè)shell命令 linux文本系列-file命令用法

    這篇文章主要介紹了一天一個(gè)shell命令 linux文本系列-file命令用法,需要的朋友可以參考下
    2016-06-06
  • Linux文件查找和解壓縮命令詳解

    Linux文件查找和解壓縮命令詳解

    這篇文章主要介紹了Linux文件查找和解壓縮命令,文件搜索查找包括按照名字搜索,按照文件所屬`主用戶`搜索,本文給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧
    2024-02-02
  • shell腳本批量刪除es索引的方法

    shell腳本批量刪除es索引的方法

    今天小編就為大家分享一篇關(guān)于shell腳本批量刪除es索引的方法,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧
    2019-03-03
  • 建立基于虛擬用戶的VSftpd服務(wù)

    建立基于虛擬用戶的VSftpd服務(wù)

    這篇文章主要介紹了建立基于虛擬用戶的VSftpd服務(wù)的相關(guān)資料,需要的朋友可以參考下
    2015-09-09
  • shell腳本打印日期時(shí)間的實(shí)現(xiàn)示例

    shell腳本打印日期時(shí)間的實(shí)現(xiàn)示例

    在shell 中,可以使用 `date` 命令打印系統(tǒng)時(shí)間,本文主要介紹了shell腳本打印日期時(shí)間的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-09-09

最新評(píng)論