zoukankan      html  css  js  c++  java
  • linux 根据文件大小查找文件

    inux下的find命令用来查找文件,通过man find就知道它是无所不能的。所以按照文件大小来查找文件就不在话下。从man find搜索size,可以看到如下信息:

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

    注意:默认单位是b,而它代表的是512字节,所以2表示1K,1M则是2048,如果不想自己转换,可以使用其他单位,如c、K、M等。

    例子:查找当前目录下文件大小为2048(2k)字节的文件

    find ./ -size 4
    或
    find ./ -size 2048c
    或
    find ./ -size 2K

    上述查找文件是等于指定大小的,那能不能查询大于或小于某个指定值的文件呢,答案是肯定,例如:

    查找大于2K的文件,+ 表示大于
    find ./ -size +2048c
    
    查找小于2K的文件,- 表示小于
    find ./ -size -2048c -type f

    找到的文件可以进一步操作!

    如: 查找小于1000字节的文件删除之

     find ./ -size -1000c -type f -exec rm -rf {} ;
  • 相关阅读:
    HDU 1087 Super Jumping! Jumping! Jumping!
    HDU 1159 Common Subsequence
    HDU 1003 Maxsum
    HDU 2604 Queuing
    HDU 2045 不容易系列之(3)—— LELE的RPG难题
    HDU 2501 Tiling_easy version
    HDU 2050 折线分割平面
    HDU 2018 母牛的故事
    HDU 2046 骨牌铺方格
    HDU 2044 一只小蜜蜂...
  • 原文地址:https://www.cnblogs.com/feng18/p/6004339.html
Copyright © 2011-2022 走看看