递归数特定文件BASH [英] Recursively count specific files BASH

查看:117
本文介绍了递归数特定文件BASH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是编写一个脚本来递归当前工作目录和子dirctories搜索和打印普通的文件数量,目录的数量,块特殊文件数量,性质特殊的计数的计数文件以及FIFO的数量和符号链接的数量。我必须使用与[[]]条件测试。问题是,我不太知道如何甚至开始。

My goal is to write a script to recursively search through the current working directory and the sub dirctories and print out a count of the number of ordinary files, a count of the directories, count of block special files, count of character special files,count of FIFOs, and a count of symbolic links. I have to use condition tests with [[ ]]. Problem is I am not quite sure how to even start.

我试过类似以下内容搜索所有普通文件,但我不知道如何准确地递归工作在bash脚本编程:

I tried the something like the following to search for all ordinary files but I'm not sure how recursion exactly works in BASH scripting:

function searchFiles(){
    if [[ -f /* ]]; then
        return 1
    fi
}
searchFiles
echo "Number of ordinary files $?"

但我得到0结果。这个谁能帮助?

but I get 0 as a result. Anyone help on this?

推荐答案

您为什么不使用找到

$ # Files
$ find . -type f | wc -l
327
$ # Directories
$ find . -type d | wc -l
64
$ # Block special
$ find . -type b | wc -l
0
$ # Character special
$ find . -type c | wc -l
0
$ # named pipe
$ find . -type p | wc -l
0
$ # symlink
$ find . -type l | wc -l
0

这篇关于递归数特定文件BASH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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