Поиск файла с фиксированным размером файла (> 0) в Unix / Linux - PullRequest
2 голосов
/ 06 мая 2010

У меня есть список файлов, который выглядит следующим образом

  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

Ответы [ 3 ]

4 голосов
/ 06 мая 2010

Вам нужно добавить суффикс 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.
1 голос
/ 06 мая 2010

Это то, что я получаю в 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).
1 голос
/ 06 мая 2010
 -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.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...