How To Find the largest files and directories in Linux

Find the largest files and directories in Linux

Find The Largest Files And Directories In Linux

Here is a handy little list of command lines for Linux to find out which files and directories take up the most space, just to clean up. So, find the largest files and directories in linux with these commands.

Replace / home / manu with the directory of your choice. Don’t worry afterwards if it takes a little while.

du -hms / home / manu / * | sort -nr | head

There are other command I found out after searching a while. These are:

Find Command to find the largest files and directories

o search for files with size greater than 50 MB, in the current working directory , you would run the following command:

$ sudo find . -xdev -type f -size +50M

As output, this command will show a list of files without any additional information. Though path will be mentioned.

/var/lib/libvirt/images/centos-7-desktop_default.img
/var/lib/libvirt/images/bionic64_default.img
/var/lib/libvirt/images/win10.qcow2
/var/lib/libvirt/images/debian-9_default.img
/var/lib/libvirt/images/ubuntu-18-04-desktop_default.img
/var/lib/libvirt/images/centos-7_default.img

We can also use find command in combination with the the tools/command like ls or sort to perform operations on those files.

In the example below, we are going to pass the output of the find command to ls that will print the size of each found file and then pipe that output to the sort command to sort it based on the 5th column which is the file size.

find . -xdev -type f -size +50M -print | xargs ls -lh | sort -k5,5 -h -r

The output will look something like this:

-rw-------  1 root   root 40967M Jan  5 14:12 /var/lib/libvirt/images/win10.qcow2
-rw-------  1 root   root  3725M Jan  7 22:12 /var/lib/libvirt/images/debian-9_default.img
-rw-------  1 root   root  1524M Dec 30 07:46 /var/lib/libvirt/images/centos-7-desktop_default.img
-rw-------  1 root   root   999M Jan  5 14:43 /var/lib/libvirt/images/ubuntu-18-04-desktop_default.img
-rw-------  1 root   root   562M Dec 31 07:38 /var/lib/libvirt/images/centos-7_default.img
-rw-------  1 root   root   378M Jan  7 22:26 /var/lib/libvirt/images/bionic64_default.img

If the output contains a lot of lines of information you can use the head command to print only the first 10 lines:

find . -xdev -type f -size +50M -print | xargs ls -lh | sort -k5,5 -h -r | head

Have a look at these too:

Leave a Reply