2010-05-06 277 views
2

我有文件的列表,看起来像这样查找文件具有固定的文件大小(> 0)的Unix/Linux

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 
+0

什么是大小衡量?它在磁盘或大小上的大小? – 2010-05-06 03:03:21

回答

4

您需要通过“C”的后缀大小53。按照发现的联机帮助 -

-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. 
1
-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。

1

这是我所得到的在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). 
相关问题