How to Search File with Specific File Size

clean-your-room

Assalamualaikum..

Cleaning up your machine is very important to make sure your box is running in optimum performance and healthy. You may use command df -h regularly to check your partition size. But it will not tell you which file is growing and consume the space. Of course you can go through df -h and issue the command du -sh to check the size. But using this way, you need to crawl all over the path one by one. This is not really convenient. Below command will show you how to find out which file is taking space in your machine by using the specific file size.

# su - root
# find / -xdev -type f -size +100M

above command will search all files that having size bigger than 100MB in / partition. You can change the value.

The following command will find you the top 50 largest files (>100M) on your filesystem, and sort by the biggest:

find / -xdev -type f -size +100M -exec du -sh {} ';' | sort -rh | head -n50

For all files and directories, it’s even easier:

du -ahx / | sort -rh | head -20
(the -x flag is what’s required to constrain du to a single filesystem)

If you’re not using GNU sort (from coreutils), use it without -h:

du -ax / | sort -rn | head -20
For currently directory only (for quicker results), replace / with .

happy linuxing

wassalam..

..

Advertisements
This entry was posted in Linux and tagged , , , . Bookmark the permalink.