Finding a file with a fixed file size (> 0) on Unix / Linux

I have a list of files that looks like

  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

      

What I want to do is find files with the exact size 53

. But why did this command fail?

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

      

This works well, although if I just want to find a file with size 0 with this command:

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

      

+2


a source to share


3 answers


You need to suffix size 53 with 'c'. How to find the manpage -



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

      

+4


a source


 -size n[ckMGTP]
         True if the file size, rounded up, in 512-byte blocks is n.  If
         n is followed by a c, then the primary is true if the file size
         is n bytes (characters).  Similarly if n is followed by a scale
         indicator then the file 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)

      



You need to use -size 53c.

+1


a source


This is what I get on Mac OS 10.5

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

      

+1


a source







All Articles