Site icon DesignLinux

Find Large Files in Linux

Find Large Files in Linux

In Linux, it is very necessary to find the unnecessary files and free up them from your hard disk. Usually, Linux systems run out of disk space due to large log or backup files. This tutorial explains how to find the large files and directories in Linux systems using the find and du command.

Find Large Files Using the find Command

The find command is very useful tools in the Linux systems. Using it you can search for files and directories with specific criteria.

For example, if you want to find files with size greater than 200MB in current working directory, type:

sudo find . -xdev -type f -size +200M

You should replace . dot with the path if you want to find in specific directory.

The above command will show a list of files without any additional information.

/home/tecnstuff/bkp.zip
/home/tecnstuff/image1.jpg

You also can use find command with combination of other commands such as ls or sort to perform operations on those files.

For example, we will pass the output of the find command to ls which will show the size of the each found file.

find . -xdev -type f -size +100M -print | xargs ls -lh

It will show the below output:

-rw------- 1 tecnstuff tecnstuff 365M Dec 28 01:10 /home/tecnstuff/bkp.zip
-rw------- 1 tecnstuff tecnstuff 290M Mar 7 20:06 /home/tecnstuff/image1.jpg

If there are more lines in output you can combine head command to show only first 10 line as given below:

find . -xdev -type f -size +100M -print | xargs ls -lh | head

Following is the explaination of the command:

The find command has lot of powerful options. For example, you can search for large files that are older than specific days, large files with a specific extension or large files that belong to a particular user.

Find Large Files and Directories Using the du Command

Generally, the du command is used to finding directories and files that consume large amounts of disk space.

The below command will display the list of largest files and directories:

du -ahx . | sort -rh | head -5
35G .
24G ./images
12G ./data

Let’s break down the command:

The du command includes more other options.

Conclusion

It is necessary to find large files and free it up, when your disk is full and getting out of space.

If you have any questions or remarks, please leave a comment below.

Exit mobile version