Detailed explanation of finding file instances based on file size in Linux

零下一度
Release: 2017-06-28 11:19:57
Original
2125 people have browsed it

You will know through man find that it is omnipotent. So it’s easy to find files by file size. Searching for size from man find, you can see the following information:

-size n[cwbkMG]
a 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)


Note : The default unit is b, and it represents 512 bytes, so 2 means 1K, and 1M is 2048. If you don’t want to convert it yourself, you can use other units, such as c, K, M, etc.

Example: Find a file with a file size of 2048 (2k) bytes in the current directory

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

The above search file is equal to the specified size. Can we search for files larger or smaller than a specified value? The answer is yes, for example:

Find files larger than 2K, + means larger than
find ./ -size +2048c

Find files smaller than 2K, - means smaller than
find ./ -size -2048c -type f

The found files can be further manipulated!

For example: Find and delete files less than 1000 bytes

find ./ -size -1000c -type f -exec rm -rf {} \;


The above is the detailed content of Detailed explanation of finding file instances based on file size in Linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template