Operations 5 min read

Why Deleting Apache Logs Doesn’t Free Disk Space and How to Fix It

This guide explains why removing Apache/Tomcat log files while the services are running fails to release disk space, analyzes the inode‑locking behavior, and provides practical solutions such as restarting the server, truncating logs, and using scheduled cleanup commands.

BiCaiJia Technology Team
BiCaiJia Technology Team
BiCaiJia Technology Team
Why Deleting Apache Logs Doesn’t Free Disk Space and How to Fix It

1. Scenario : A web server running Apache/Tomcat reports full disk space with df, yet after deleting log files the space remains full; du -sh /* shows the total file size far below the disk capacity.

2. Problem analysis : Deleting logs while Apache/Tomcat is active does not free space because the running process still holds the log file’s inode. The file is merely unlinked, so the allocated blocks stay occupied.

3. Solution : Restart Apache/Tomcat, or truncate the log file without deleting it.

4. Extended – better log‑deletion methods :

(1) Delete logs older than three days via a scheduled task, e.g.:

find /data/www/tomcat-webserver/logs/ -type f -mtime +3 | xargs rm -f
find /data/www/tomcat-webserver/logs/*log* -type f -mtime +3 | xargs rm -f
find /data/www/tomcat-webserver/logs/ -type f -mtime +3 -exec rm -f {} \;

(2) Clear the current log without removing the file:

cat /dev/null > ./logs/test.log
> ./logs/test.log

5. Production simulation :

Install Apache and modify the log path:

yum install httpd
sed -i 's#CustomLoglogs/access_log combined#CustomLog /app/logs/access_log combined#g' /etc/httpd/conf/httpd.conf

Create a large file to simulate a small‑capacity disk:

dd if=/dev/zero of=/mnt/apachelog bs=10K count=10
mkfs.ext4 /mnt/apachelog

Mount the loop device to the log directory:

mkdir -p /app/logs
mount -o loop /mnt/apachelog /app/logs/

Start Apache and generate heavy traffic to fill the disk:

/etc/init.d/httpd start
for i in $(seq 10000); do curl -s http://192.168.1.200; done

Simulate normal log deletion:

rm -f /app/logs/access_log
df -h

The df -h output shows the filesystem still reports high usage, and lsof | grep access_log reveals processes (httpd) still holding the deleted log file.

6. Final resolution :

(1) Restart Apache to release the inode: /etc/init.d/httpd restart (2) Truncate the log file directly:

> /app/logs/access_log
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

operationsApacheLog Managementdisk space
BiCaiJia Technology Team
Written by

BiCaiJia Technology Team

BiCaiJia Technology Team

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.