Home > Article > Operation and Maintenance > Detailed explanation of finding file instances based on file size in Linux
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!