- Forums
- Linux Hosting
- Linux Command Display The Amount Of Space Being Used
This Page Has A Tutorial That Will Show You A Linux Command Display The Amount Of Space Being Used [1309], Last Updated: Mon Jun 24, 2024
Webune Tutorials
Sun Dec 06, 2009
0 Comments
601 Visits
If you have a Webune Linux Dedicated server you might find this short tutorial helpful.
Webune Offers reliable dedicated servers at affordable prices. If you are a Webune customer, be sure to access your system as root.
Knowing how much space you have available in your system is very important. specially if you are running a website on your server. if you have such services as PHP, MySQL and Apache HTTPD all these services create error logs and access logs which can overwhelm your system and your hard drive. cleaning frequently or backing up your logs is necessary to keep your UNIX/Linux system in good shape. There are times when a script or a system generated error will tell you that you dont have any more space in your system to continue. this happens when there is no more space in your hard drive for the application to write data into your harddrive.
but then you ask yourself.. which system is taking all the space? well, we are going to show you how you can trouble shoot this.
lets say for example, in our scenario that the /var/log/httpd-error.log file is like 90G in size and well, if you delete this file you will save 90G of space in your harddrive. this is how you can troubleshoot and find out which files are taking most of the space in your system.
the first thing to do is to login to your linux server as root
then execute this command to go to the root directory:
SHELL COMMAND:
cd /
now execute this command to see which directory is using the most space:
SHELL COMMAND:
du -hc --max-depth=1
you should get a list like this example:
OUTPUT:
[root@hostname /][root@hostname /]# du -hc --max-depth=1
0 ./net
1.6G ./usr
16K ./lost+found
515M ./proc
8.0K ./misc
90G ./var
112K ./dev
8.0K ./mnt
66M ./lib
8.0K ./selinux
7.3M ./bin
77M ./root
4.2M ./boot
28K ./tmp
2.7M ./backups
20M ./sbin
8.0K ./media
8.0K ./srv
0 ./sys
43M ./etc
42M ./home
8.0K ./opt
3.0G .
3.0G total
as you can see the var/ directory has the biggest size with 90G, so now you can cd to the log/ directory:
SHELL COMMAND:
cd /var/
and now display which directory in the var directory has the biggest size:
SHELL COMMAND:
du -hc --max-depth=1
OUTPUT:
[root@hostname /]# du -hc --max-depth=1
0 ./net
1.6G ./usr
16K ./lost+found
515M ./proc
8.0K ./
89G ./log
90.0G total
as you can see from the output, log/ has the most space being used from all the other directories. so now cd to the log directory:
SHELL COMMAND:
cd /var/log/
and now display which directory in the log directory has the biggest size:
SHELL COMMAND:
du -hc --max-depth=1
OUTPUT:
[root@hostname /]# du -hc --max-depth=1
1.6G ./web
16K ./firewall
515M sam.log
8.0K dberror.log
88G httpd-error.log
90.0G total
now that you know which file is taking most of the disk space in your system you have two options.
1. you can delete the file
2. you can empty the file or just remove all BUT the last 5 lines. if you want to learn how to reduce the file size, continue with this tutorial on the next step:
How To Empty A File In Linux