How to find the largest files/folders on the server

Post Reply
User avatar
myVesta
Site Admin
Posts: 946
Joined: Fri Jun 19, 2020 9:59 am
Has thanked: 9 times
Been thanked: 6 times

To find the largest files on the server:
Logged in as 'root', in your SSH console run:

Code: Select all

find / -type f -ls 2>/dev/null | grep -v ' /proc/\| /var/lib/\| /boot' | awk '{print $7" "$5":"$6" ("$9"."$8"/"$9":"$10") "$11 $12 $13 $14 $15 $16 $17 $18 $19 $20}' | sort -h | tail -50 | column -t
Or scan only /home :

Code: Select all

find /home/ -type f -ls 2>/dev/null | awk '{print $7" "$5":"$6" ("$9"."$8"/"$9":"$10") "$11 $12 $13 $14 $15 $16 $17 $18 $19 $20}' | sort -h | tail -50 | column -t
All commands from this tutorial can take a while to execute, so be patient.

------------------

Finding largest folder is a bit complicated .
You must start from the root of your server ( / folder) and then see largest folder at first level, and then go down to the inner folder levels.

Code: Select all

du --max-depth=1 -c -m -x / | sort -n
Output will be:

Code: Select all

1	/lost+found
1	/media
1	/mnt
1	/nonexistent
1	/opt
1	/srv
12	/etc
31	/tmp
109	/root
2400	/usr
127523	/var
269009	/home
407067	/
407067	total
(given values are in megabytes)

From this output, we can conclude that /home is the largest folder.

Now we should check /home sub-folders:

Code: Select all

du --max-depth=1 -c -m -x /home | sort -n
Output will be:

Code: Select all

1	/home/admin
1	/home/blank
643	/home/sites
268365	/home/myuser
269009	/home
269009	total
From this output, we can conclude that /home/myuser is the largest sub-folder.

Now we should check /home/myuser sub-folders:

Code: Select all

du --max-depth=1 -c -m -x /home/myuser | sort -n
... etc ... until you locate final folder or group of folders that you can consider as problematic large.
Post Reply