简体   繁体   English

通过bash查找特定文件的数量

[英]Finding the number of specific files via bash

Fill in the dots on the next Unix command, like so, the standard out gives an overview per file type with the number of files in the /dev directory.在下一个 Unix 命令上填写点,像这样,标准输出给出了每个文件类型的概述,以及 /dev 目录中的文件数。 In this overview, all filetypes must be listed in descending order of the number of found files of the certain type.在此概述中,所有文件类型必须按找到的特定类型文件数量的降序列出。 If there are filetypes with an equal number of files, they must be listed in alphabetical order.如果文件类型具有相同数量的文件,则它们必须按字母顺序列出。

$ find /dev -ls | …
  7 c
  6 l
  3 d

Tips:提示:

The part already given with the find-command, also finds hidden files in the directory. find-command 已经给出的部分也可以找到目录中的隐藏文件。

With help of the cut-command, you can select a certain part of a line, the two most important options are -f and -d.借助剪切命令,您可以选择一行的某个部分,两个最重要的选项是 -f 和 -d。 The first one splits the lines in columns.第一个将行拆分为列。 By default, the tab-character is used.默认情况下,使用制表符。 With the option -d you can specify a custom delimiter.使用选项 -d 可以指定自定义分隔符。

tr, sort and uniq might be useful. tr、sort 和 uniq 可能有用。

What I have so far:到目前为止我所拥有的:

find /dev -ls | tr \\t " " | tr -s " " | cut -f3 -d ' ' | cut -c-1 | sort | uniq -c | sort -r

But this doesn't seem to work...但这似乎不起作用......

Thanks in advance.提前致谢。

我喜欢在这种情况下使用 awk 而不是 tr

 find /dev -ls | gawk '{ c=substr($3,1,1) ; x[c]++ } END { for(y in x) print x[y] " " y }' | sort -n

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM