Linux递归统计当前目录下普通文件的数量: ls -lR |grep "^-"|wc -l 或者: ls -lR | grep -c "^-" 递归统计方式: ls -lR Linux常见的文件类型有:普通文件、目录文件、字符设备文件和块设备文件、符号链接文件等,其中: 1 普通文件的文件权限第一个字符为"-" 2 目录文件的文件权限第一个字符为"d" 3 字符设备文件的文件权限第一个字符为"c"; 4 块设备文件的文件权限第一个字符为"b" 5 符号链接文件的文件权限第一个字符为"s" 另一种思路: 用find命令,效率比grep高很多: find ./ -type f | wc -l 说明 ./ 意思是查询当前目录下对应的文件 wc -l wc命令(word characters)统计文件字符数,参数 "-l" 是统计行数 man命令中对于"-type f"中的"f"参数的解释如下: File is of type c: b block (buffered) special c character (unbuffered) special d directory p named pipe (FIFO) f regular file l symbolic link; this is never true if the -L option or the -follow option is in effect, unless the symbolic link is broken. If you want to search for symbolic links when -L is in effect, use -xtype. s socket D door (Solaris) 查看当前目录下的文件夹目录个数(不包含子目录中的目录): ls -l | grep "^d" | wc -l 查询当前目录下所有目录及子目录个数: ls -lR | grep "^d" | wc -l grep "^d"表示目录,"^-"表示普通文件 举个例子: 查询当前路径下的指定前缀名的目录下的所有文件数量 # 例如:统计所有以“20161124”开头的目录下的全部文件数量 ls -lR 20161124*/ | grep "^-" | wc -l |
|
来自: LibraryPKU > 《OS》