用于计算进入目录的文件数的 Shell 脚本 [英] Shell Script to count the number of files coming in a directory

查看:26
本文介绍了用于计算进入目录的文件数的 Shell 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下场景 -

远程服务器(例如,Server1)使用 FTP 将一些文件推送到另一个服务器(例如,Server 2).然后它更新 Server2 上的数据库,然后自动删除推送的文件.文件会在目录中保留几秒钟.

A remote server(say, Server1) pushes some files into another server(say, Server 2), using FTP. It then updates the database at Server2 and then pushed files are deleted automatically. The files remains in the directory for just few seconds.

我必须编写一个 SHELL SCRIPT 来计算进入目录的这些文件的数量(以分钟为单位).

I have to write a SHELL SCRIPT which will count the number of these files coming in the directory (say in minutes).

PS : Server1 和 Server2 在同一网络路径上

PS : Server1 and Server2 are on the same network path

推荐答案

这将统计最后一分钟内修改的文件.

This will count the files modified during the last minute.

find / -mmin 1|wc -l

每分钟运行一次.

使用 ftpfscurlftpfs.

更新:如果您害怕在几秒钟内丢失一些文件,您可以使用文件的时间戳.您必须依次触摸两个文件才能找到比 t0 新且比 t1 旧的文件.

Update: If you fear to loose some files during a seconds fraction you can use the time stamps of files. You have to touch two files in oder to find those files newer than t0 and older than t1.

初始化开始时间:

touch t0

之后,您可以在循环中执行此操作:

After that you can execute this in a loop:

touch t1
find / -newer t0 -a -not -newer t1 | wc -l
mv t1 t0

这可确保您不会丢失任何文件.

This makes sure that you do not loose any files.

这篇关于用于计算进入目录的文件数的 Shell 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆