【问题标题】:Finding File WIth Fixed File Size (>0) in Unix/Linux在 Unix/Linux 中查找具有固定文件大小 (>0) 的文件
【发布时间】:2010-05-06 03:01:16
【问题描述】:

我有一个看起来像这样的文件列表

  4 -rw-r--r-- 1 neversaint hgc0746         53 May  1 10:37 SRX016372-SRR037477.est_count
  4 -rw-r--r-- 1 neversaint hgc0746         53 May  1 10:34 SRX016372-SRR037478.est_count
  4 -rw-r--r-- 1 neversaint hgc0746         53 May  1 10:41 SRX016372-SRR037479.est_count
  0 -rw-r--r-- 1 neversaint hgc0746          0 Apr 27 11:16 SRX003838-SRR015096.est_count
  0 -rw-r--r-- 1 neversaint hgc0746          0 Apr 27 11:32 SRX004765-SRR016565.est_count

我想要做的是找到大小正好为53 的文件。但是为什么这个命令失败了?

$ find . -name "*.est_count" -size 53 -print

如果我只想用这个命令查找大小为 0 的文件,它会很好用:

 $ find . -name "*.est_count" -size 0 -print

【问题讨论】:

  • 尺寸是多少?它是磁盘大小还是大小?

标签: linux unix find


【解决方案1】:

您需要在大小 53 后加上“c”。根据查找的手册页 -

-size n[cwbkMG]
          File uses n units of space.  The following suffixes can be used:

          `b'    for 512-byte blocks (this is the default if no suffix  is
             used)

          `c'    for bytes

          `w'    for two-byte words

          `k'    for Kilobytes (units of 1024 bytes)

          `M'    for Megabytes (units of 1048576 bytes)

          `G'    for Gigabytes (units of 1073741824 bytes)

          The  size  does  not  count  indirect  blocks, but it does count
          blocks in sparse files that are not actually allocated.  Bear in
          mind  that the `%k' and `%b' format specifiers of -printf handle
          sparse  files  differently.   The  `b'  suffix  always   denotes
          512-byte  blocks and never 1 Kilobyte blocks, which is different
          to the behaviour of -ls.

【讨论】:

    【解决方案2】:
     -size n[ckMGTP]
             True if the file's size, rounded up, in 512-byte blocks is n.  If
             n is followed by a c, then the primary is true if the file's size
             is n bytes (characters).  Similarly if n is followed by a scale
             indicator then the file's size is compared to n scaled as:
    
             k       kilobytes (1024 bytes)
             M       megabytes (1024 kilobytes)
             G       gigabytes (1024 megabytes)
             T       terabytes (1024 gigabytes)
             P       petabytes (1024 terabytes)
    

    你需要使用 -size 53c。

    【讨论】:

      【解决方案3】:

      这就是我在 A Mac OS 10.5 上得到的

      > man find
      ...
      -size n[c]
               True if the file's size, rounded up, in 512-byte blocks is n.  If n
               is followed by a c, then the primary is true if the file's size is n
               bytes (characters).
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-07-13
        • 1970-01-01
        • 2012-01-04
        • 1970-01-01
        • 2012-01-26
        • 1970-01-01
        相关资源
        最近更新 更多