Linux 统计当前文件夹、文件的数目

    xiaoxiao2023-03-24  2

     

    [root@eccs_web www]# ll

    总用量 428

    -rw-r--r--  1 root root 387867 11  6 07:50 adminer.php

    drwxrwxrwx 12 root root   4096 11  6 07:50 eccs

    -rw-r--r--  1 root root     56 11  6 07:50 index.php

    -rw-r--r--  1 root root  29457 11  6 07:50 memcache.php

    -rwxr-xr-x  1 root root    171 11  6 07:50 rs1.sh

    -rwxr-xr-x  1 root root    483 11  6 07:50 run.sh

     

    1、统计当前文件的数目

    [root@eccs_web www]# ls -l | grep "^-" |wc -l

    5

     

    [root@eccs_web www]# find ./ -type f -maxdepth 1 | wc -l

    find: 警告: 您在非选项参数 -type 后定义了 -maxdepth 选项,但选项不是位置选项 (-maxdepth 影响在它之前或之后的指定的比较测试)。请在其它参数之前指定选项。

     

    5

     

    2、统计当前目录下及其子目录下的所有文件数

    [root@eccs_web www]# ls -lR | grep "^-" |wc -l

    988

     

    [root@eccs_web www]# find ./ -type f  | wc -l

    988

     

    1、统计当前文件夹的数目

    [root@eccs_web www]# ls -l | grep "^d" |wc -l

    1

     

    [root@eccs_web www]# find . -type d -maxdepth 1

    find: 警告: 您在非选项参数 -type 后定义了 -maxdepth 选项,但选项不是位置选项 (-maxdepth 影响在它之前或之后的指定的比较测试)。请在其它参数之前指定选项。

     

    .

    ./eccs

    [root@eccs_web www]# find ./ -type d -maxdepth 1 |wc -l

    find: 警告: 您在非选项参数 -type 后定义了 -maxdepth 选项,但选项不是位置选项 (-maxdepth 影响在它之前或之后的指定的比较测试)。请在其它参数之前指定选项。

     

    备注:查询的结果需要减一,因为多了一个当前目录“.”

     

    2、统计当前目录下包括子目录下的所有目录

    [root@eccs_web www]# ls -lR | grep "^d" |wc -l

    131

     

    [root@eccs_web www]# find ./ -type d  | wc -l

    132

    备注:查询的结果需要减一,因为多了一个当前目录“.”

    统计当前目录下的文件及文件数

    [root@eccs_web www]# ls -l | wc -l

    7

    备注:要对得出的结果减一,因为多了一行总用量

     

     

     

    转载请注明原文地址: https://ju.6miu.com/read-1200209.html
    最新回复(0)