仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1617|回复: 9
打印 上一主题 下一主题

[shell编程] 带来一篇统计以后目次下目次和文件的各自数目剧本

[复制链接]
透明 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-14 20:14:45 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
欢迎大家来到仓酷云论坛!Linux下怎样统计以后目次下文件有几个,目次又有几个呢?

上面用shell写一个剧本,安排在以后目次下,实行便可。

#!/bin/bash

#剧本称号dir
#界说一个函数fun_directory

fun_directory(){
let"filenum=0"
let"dirnum=0"

foriin$(ls)
do
if[-d$i]
then
letdirnum+=1
else
letfilenum+=1
fi
done

echo"Thenumberofdirectorysis$dirnum"
echo"Thenumberoffilesis$filenum"

}

#挪用函数

fun_directory




我们测试一下:

[root@localhostscripts]#pwd
/root/scripts
[root@localhostscripts]#ll|sort
drwxr-xr-x2rootroot409606-1210:44charpter8
drwxr-xr-x2rootroot409606-1312:34aaa
-rw-r--r--1rootroot10506-1308:56file1
-rw-r--r--1rootroot10606-1214:248-9
-rw-r--r--1rootroot12106-1209:36jiu
-rw-r--r--1rootroot13306-1311:09temp
-rw-r--r--1rootroot21006-1213:408-8
-rw-r--r--1rootroot22206-1211:518-6
-rw-r--r--1rootroot24706-1211:358-5
-rw-r--r--1rootroot27306-1213:138-7
-rw-r--r--1rootroot29206-1210:578-1
-rw-r--r--1rootroot30906-1214:518-11
-rw-r--r--1rootroot31406-1215:018-17
-rw-r--r--1rootroot31706-1312:10test
-rw-r--r--1rootroot5106-1211:008-2
-rw-r--r--1rootroot5306-1308:51file
-rw-r--r--1rootroot6706-1310:1710-4
-rw-r--r--1rootroot7806-1310:09test.out
-rwxr-xr-x1rootroot10306-1211:068-3
-rwxr-xr-x1rootroot12406-1310:0210-32
-rwxr-xr-x1rootroot30406-1312:47dir
-rwxr-xr-x1rootroot31606-1211:218-4
#实行剧本
[root@localhostscripts]#shdir
Thenumberofdirectorysis2
Thenumberoffilesis20
[root@localhostscripts]#




能够看到,数据统计是正确的。
如果您觉得本篇CentOSLinux教程讲得好,请记得点击右边漂浮的分享程序,把好文章分享给你的好朋友们!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-12 21:18

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表