Jump to content

Featured Replies

Posted
comment_15

In this tutorial we’ll learn how to find big files in Linux, you can use the find command with the du command to search for the files. Here’s how to do it:

Open a terminal/ssh window.

Navigate to the directory where you want to search for big files. For example, to search for big files in your server root / directory, type:

cd /


Type the following command to list all files in the current directory and its subdirectories, sorted by size:

du -ah . | sort -rh | head -n 30


This command uses the du command to calculate the size of each file and the sort command to sort the results in reverse order. The head command is used to show only the first 30 results.

The output will show the size of each file in a human-readable format (such as “1.5M” or “10G”) and the path to the file.

You can modify the command to search for big files in a specific directory or to show more or fewer results. For example, to search for big files in the /home and /var/log directories and show the first 100 results, type:

du -ah /home | sort -rh | head -n 100
#or
du -ah /var/log | sort -rh | head -n 100


Bonus command:
To find big files all over the server disk / :

find / -mount -size +1024k -type f -exec ls -alh {} \;|sort -rnb -k 5|more
example :

[root@server ~]# find / -mount -size +1024k -type f -exec ls -alh {} \;|sort -rnb -k 5|more
-rw-r--r-- 1 clamupdate clamupdate 185M May  6 04:23 /var/lib/clamav/daily.cld
-rw-r--r-- 1 clamupdate clamupdate 163M Sep 22  2021 /var/lib/clamav/main.cvd
-rw------- 1 root mail 137M May  6 16:09 /var/spool/mail/root

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now