计算每天文件夹中的文件数

tas*_*ski 11 command-line find

我可以找到文件夹中所有文件的数量,但我得到了相当多的数量。

find . -type f | wc -l      #find number of files in DIR
ls -lrt                     #list all files order by date  
Run Code Online (Sandbox Code Playgroud)

如何找到标准日的文件数?

所以,结果应该是这样的:

# left number is number of files and right is one day.

109294 2016-06-27
101555 2016-06-26
88123  2016-06-25 
... etc. 
Run Code Online (Sandbox Code Playgroud)

hee*_*ayl 22

您可以使用 的printf操作find仅以所需格式打印修改时间,然后使用sort和来执行此操作uniq

find . -type f -printf '%TY-%Tm-%Td\n' | sort | uniq -c
Run Code Online (Sandbox Code Playgroud)
  • -printf '%TY-%Tm-%Td\n'以例如2015-05-23格式打印文件的修改时间

  • sort对输出进行排序并按uniq -c日期进行计数

例子:

~/foobar% find . -type f -printf '%TY-%Tm-%Td\n' | sort | uniq -c
      3 2004-06-29
      1 2004-08-23
      1 2004-09-15
      1 2004-09-18
      1 2005-07-24
      1 2006-02-05
      2 2008-06-25
      3 2008-12-31
      1 2009-03-13
      1 2009-04-30
      1 2010-04-04
      2 2010-09-01
      8 2011-07-13
     15 2011-08-27
      3 2011-11-03
      3 2014-10-08
Run Code Online (Sandbox Code Playgroud)

  • 注意:这些可以通过 Gnuplot 使用 `find 以图形方式查看。-type f -printf '%TY-%Tm-%Td\n' 2</dev/null | 排序 | uniq -c | 尾 -n +2 | gnuplot -p -e "set xdata time; set timefmt \"%Y-%m-%d\";set xtics rotation; plot '-' using 2:1 with pulses"` (2认同)