![](/img/trans.png)
[英]How to list the files and folders in a directory with its total size in Linux?
[英]Linux:How to list the information about file or directory(size,permission,number of files by type?) in total
假设我留在当前目录中,我想列出所有文件的总数,以及大小、权限以及按类型划分的文件数。
这是示例输出:
这是一个示例:
打印有关“/home/user/poker”的信息
文件总数:83
pdf文件:5
html文件:9
文本文件:15
未知:5
注意:任何没有扩展名的文件都可以被认为是未知的。
我希望使用一些简单的命令,如 ls、cut、sort、unique ,(只是示例)将每个不同的扩展名放在文件中并使用 wc -l 来计算行数
还是我需要使用 grep、awk 或其他东西?
希望得到大家的建议。谢谢!
file
仅输出 mimetype 并将其传递给awk
。file * -ib | awk -F'[;/.]' '{print $(NF-1)}' | sort -n | uniq -c
在我的主目录上,它会生成此输出。
35 directory
3 html
1 jpeg
1 octet-stream
1 pdf
32 plain
5 png
1 spreadsheet
7 symlink
1 text
1 x-c++
3 x-empty
1 xml
2 x-ms-asf
4 x-shellscript
1 x-shockwave-flash
text/x-c++
和text/plain
应该在同一个使用这个 file * -ib | awk -F'[;/.]' '{print $1}' | sort -n | uniq -c
6 application
6 image
45 inode
40 text
2 video
根据需要更改{print $1}
部分以获得适当的输出。
你需要bash 。
files=(*)
pdfs=(*.pdf)
echo "${#files[@]}"
echo "${#pdfs[@]}"
echo "$((${#files[@]}-${#pdfs[@]}))"
find . -type f | xargs -n1 basename | fgrep . | sed 's/.*\\.//' | sort | uniq -c | sort -n
这为您提供了文件扩展名的递归列表。 如果您只想要当前目录,请在 find 命令中添加-maxdepth 1
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.