[英]Linux:How to list the information about file or directory(size,permission,number of files by type?) in total
Suppose I am staying in currenty directory, I wanted to list all the files in total numbers, as well as the size, permission, and also the number of files by types.假设我留在当前目录中,我想列出所有文件的总数,以及大小、权限以及按类型划分的文件数。
here is the sample outputs:这是示例输出:
Here is a sample :这是一个示例:
Print information about "/home/user/poker"打印有关“/home/user/poker”的信息
total number of file : 83文件总数:83
pdf files : 5 pdf文件:5
html files : 9 html文件:9
text files : 15文本文件:15
unknown : 5未知:5
NB: anyfile without extension could be consider as unknown.注意:任何没有扩展名的文件都可以被认为是未知的。
i hope to use some simple command like ls, cut, sort, unique ,(just examples) put each different extension in file and using wc -l to count number of lines我希望使用一些简单的命令,如 ls、cut、sort、unique ,(只是示例)将每个不同的扩展名放在文件中并使用 wc -l 来计算行数
or do i need to use grep, awk , or something else?还是我需要使用 grep、awk 或其他东西?
Hope to get the everybody's advices.thank you!希望得到大家的建议。谢谢!
file
to output only mimetype and pass it to awk
.file
仅输出 mimetype 并将其传递给awk
。file * -ib | awk -F'[;/.]' '{print $(NF-1)}' | sort -n | uniq -c
On my home directory it produces this output.在我的主目录上,它会生成此输出。
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++
and text/plain
should be in same Use thistext/x-c++
和text/plain
应该在同一个使用这个 file * -ib | awk -F'[;/.]' '{print $1}' | sort -n | uniq -c
6 application
6 image
45 inode
40 text
2 video
Change the {print $1}
part according to your need to get the appropriate output.根据需要更改
{print $1}
部分以获得适当的输出。
find . -type f | xargs -n1 basename | fgrep . | sed 's/.*\\.//' | sort | uniq -c | sort -n
That gives you a recursive list of file extensions.这为您提供了文件扩展名的递归列表。 If you want only the current directory add a
-maxdepth 1
to the find command.如果您只想要当前目录,请在 find 命令中添加
-maxdepth 1
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.