Page 1 of 1

Disk usage check in detail

Posted: Sun Jun 03, 2018 4:30 pm
by Chester
Hello,

How to find detailed disk usage of a /directory in Linux server in command line?

Re: Disk usage check in detail

Posted: Sun Jun 03, 2018 4:33 pm
by Joan N
Hi,

You can use following command to check the disk usage of a directory in detail.

#du -sch /directory/*

It will show the disk usage of the files and sub directories under this directory.
--
Joan N
Linux Support Engineer.
Nixtree Solutions
Managed Full Server Backups
https://www.nixtree.com/managed-backups.php
Follow us on : https://twitter.com/nixtree

Re: Disk usage check in detail

Posted: Sun Jun 03, 2018 4:38 pm
by Chester
Hello Joan,

Thank you for the quick reply. I have tried to check the disk usage of the entire server using below command.

#du -sch /*

But I got stuck at /home directory. Since /home is mounted to different drive I already know its disk usage. So please let me know how to skip /home and get the disk usage of all other files and folders under / .

Re: Disk usage check in detail

Posted: Sun Jun 03, 2018 4:43 pm
by Joan N
Hello,

You can use following command to exclude a particular directory while using #du -sch

#du -sch /* --exclude=home

--
Joan N
Linux Support Engineer.
Nixtree Solutions
Managed Full Server Backups
https://www.nixtree.com/managed-backups.php
Follow us on : https://twitter.com/nixtree

Re: Disk usage check in detail

Posted: Sun Jun 03, 2018 4:44 pm
by Chester
Thank you, Joan.

Re: Disk usage check in detail

Posted: Mon Jun 25, 2018 8:15 am
by Micheal
Hi,

I am also facing some disk issues with my server installed with cPanel. This time I can see that my /tmp partition reached 100%. How can I resolve this? All the services are down at the moment.

root@my.hostingserver.com:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 30G 25G 3.2G 89% /
tmpfs 3.8G 3.8G 0 100% /tmp

But there is nothing in /tmp at all

root@my.hostingserver.com:~# ls -Sahl /tmp |more
total 10K
dr-xr-xr-x. 25 root root 4.0K Mar 16 04:29 ..
drwxrwxrwt. 3 root root 3.0K Mar 16 03:32 .
drwx------. 2 root root 1.0K Mar 16 04:28 mc-root

Re: Disk usage check in detail

Posted: Mon Jun 25, 2018 8:25 am
by Aaron
Hello,

You should use lsof /tmp to see if there any currently opened file. If you delete a file, while a software still have a lock on it, you won't see it anymore, but it will still have hd space assigned to it. After checking 'lsof', stopping the relevant process should free the space.

Also you can do 'tmpwatch' to clear the tmp partition. To setup /tmp to auto clean using tmpwatch

open SSH to your server, if SSH will not connect due to disk space full in tmp, reboot your server in then try again.
Once connected run the following command

Code: Select all

yum install tmpwatch -y
once tmpwatch is installed run command

Code: Select all

/usr/sbin/tmpwatch -am 12 /tmp
this will delete all files over 12 hours old

next, we will configure your server to do this automatically.

from SSH type:

Code: Select all

 crontab -e
go to the very bottom, paste it and save the file. So you can avoid such downtime issues.

Code: Select all

0 4 * * * /usr/sbin/tmpwatch -am 12 /tmp