Home » Unix command and scripts » how to find file based on size in linux

how to find file based on size in linux

While managing the space on the filesystem in Linux, We often have a question about how to find file based on the size in Linux. This can be quickly done using the find command. The general syntax is

find . -type f -size  +<size> -exec ls -al {} \;

Here are the suffixes available for the size

b – 512-byte blocks (this is the default if no suffix is used)
c – bytes
w – two-byte words
k – Kilobytes
M – Megabytes
G – Gigabytes

If you dont want to list the size, then you can use the below command also

find . -type f -size  +<size> 

How to find files greater than 1 GB

find . -type f -size +1G -exec ls -al {} \;

This will search in your current directory and subdirectories

If you want to search in /, you can put a command like

find / -type f -size +1G -exec ls -al {} \;

If you’re going to do it in your home directory, then

find ~/ -type f -size +1G -exec ls -al {} \;

You can provide specific directories also

find /u02 -type f -size +1G -exec ls -al {} \;

How to find files greater than 100 M

find . -type f -size +100M -exec ls -al {} \;

How to find empty files

find / -size 0  -exec ls -al {} \;

How to find files smaller than 100M

find . -type f -size -100M -exec ls -al {} \;

How to find the file in a range of sizes in Linux

You can find this using the operator explained above

find . -type f -size +100M -size -200M -exec ls -al {} \;

You can specify whatever size is required

See also  tee command in Unix

I hope you like this content on how to find file based on size in Linux. Please do provide feedback

Related Articles
Find command in Unix with example
Useful Unix/Linux command for Oracle DBA: This page has useful Unix command for Oracle DBA to help you in your day-to-day activites.Same are applicable for linux also.How to kill the process
Grep equivalent in Windows: Windows grep equivalent to search text: Find | findstr | power select-string. Detailed explanation with lots of examples for easy understanding
grep examples: Grep command Means – globally search regular expression. grep command in Unix is used for searching text, regular expression
split unix command: check out how to use the split Unix command, How to split the files based on lines, split the files based on bytes, Split Syntax command

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top