サイズに応じてファイルを移動する方法は?

サイズに応じてファイルを移動する方法は?

私はこれを試しました:

find . -type f -size 128 -exec mv {} new_dir/  \;

これは機能せず、エラーも発生しません。以下は、使用時にファイルがどのように見えるかの例です。stat -x

$ stat -x ./testfile | grep Size 
  Size: 128          FileType: Regular File

ベストアンサー1

私のマンページから(MacOS 10.11コンピュータ)

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

c(非標準拡張子以外のサフィックス)

サフィックスを指定しなかったので、-size 128128を意味しました。彫刻または、64Kbytesは、サイズが127 * 512 + 1(65025)から128 * 512(65536)バイトの間のファイルのみと一致します。

-size 128c-size -128c正確に128バイトのファイル、128バイト(0〜127)より小さいファイル、-size +128c128バイト(129バイト以上)より大きいファイルが必要な場合は、このオプションを使用する必要があります。

おすすめ記事