DeveloperBreeze

Clearing Unnecessary Logs on Ubuntu

Logs are crucial for diagnosing issues and monitoring the health of your system. However, over time, logs can accumulate and consume valuable disk space. Here's a step-by-step guide on how to clear unnecessary logs on Ubuntu, while ensuring you retain important system data.

1. Check Log Directories

Most system logs are stored in the /var/log/ directory. Start by listing the contents to get an overview of which logs are present:

ls /var/log/

2. View Log Sizes

Identify which log files are taking up the most space by using the du command:

du -h /var/log/

This will display the size of each log file in a human-readable format.

3. Remove Old Log Files

You can delete specific log files that you no longer need. For example, to remove an old syslog file:

sudo rm /var/log/syslog.1

Replace syslog.1 with the name of the log file you wish to delete. Always check that the log is safe to remove before proceeding.

4. Rotate Logs Automatically

Instead of manually deleting logs, use log rotation to manage file sizes and archive older logs automatically. The logrotate utility handles this:

  • Logrotate configuration files are located in /etc/logrotate.conf and /etc/logrotate.d/.

To trigger log rotation manually:

sudo logrotate -f /etc/logrotate.conf

5. Clean Package Manager Logs

The package manager stores logs that track installed and removed packages. To clean these logs, use:

sudo rm /var/log/apt/*.log

6. Clear Systemd Journal Logs

If your system uses systemd, logs are managed by journald. To clear old systemd logs, run:

sudo journalctl --vacuum-time=7d

This command will remove journal logs older than 7 days. Adjust the time parameter as needed.

7. Delete Crash Logs

Crash logs are stored in /var/crash/ and are useful for debugging. To view crash logs:

ls /var/crash/

To remove a specific crash log:

sudo rm /var/crash/example.crash

To remove all crash logs:

sudo rm /var/crash/*

8. Remove All .log and .gz Files

To delete all log files with .log or .gz extensions inside the /var/log/ directory, use:

sudo find /var/log -type f \( -name "*.log" -o -name "*.gz" \) -exec rm {} +

9. Remove Logs with Specific Patterns (e.g., .log.1, .log.2)

To also delete log files like syslog.1 or auth.log.1, modify the find command:

sudo find /var/log -type f \( -name "*.log" -o -name "*.gz" -o -name "*.log.[0-9]" \) -exec rm {} +

10. Reboot the System

After cleaning logs, it's good practice to reboot the system to ensure services restart and fresh log files are generated:

sudo reboot

Important Notes

  • Backup Logs: Before deleting, consider backing up important logs for future troubleshooting.
  • Avoid Deleting Critical Logs: Be cautious when removing logs that are essential for security and system diagnostics, such as auth.log, syslog, and kern.log.

By following this tutorial, you can free up disk space on your Ubuntu system while maintaining critical logs needed for system health monitoring.

Continue Reading

Discover more amazing content handpicked just for you

Tutorial

How to Stop SSH From Timing Out

sudo nano /etc/ssh/sshd_config

Add these lines:

Aug 21, 2025
Read More
Tutorial

✅ How to Disable MySQL Password Validation on Ubuntu 25.04

CREATE USER 'devuser'@'localhost' IDENTIFIED BY '123';
GRANT ALL PRIVILEGES ON *.* TO 'devuser'@'localhost';
FLUSH PRIVILEGES;

This should now work without any errors.

May 01, 2025
Read More
Tutorial

How to Move the MySQL Data Directory to a New Location on Ubuntu 25.04

Edit AppArmor profile for MySQL:

sudo nano /etc/apparmor.d/usr.sbin.mysqld

May 01, 2025
Read More
Tutorial

How to Install PHP, MySQL, and phpMyAdmin on Ubuntu 25.04 (LAMP Stack Setup Guide)

This script will prompt you to set a root password, remove anonymous users, disallow remote root login, remove the test database, and reload privilege tables.

Install phpMyAdmin along with necessary PHP extensions:

May 01, 2025
Read More
Tutorial

How to Fix NVIDIA Driver Issues on Ubuntu (Dell Vostro 3521)

You’ll see something like:

00:02.0 VGA compatible controller: Intel Corporation ...
	Kernel driver in use: i915
01:00.0 3D controller: NVIDIA Corporation GP107M [GeForce MX350]
	Kernel driver in use: nouveau

Apr 14, 2025
Read More
Tutorial

🛡️ Protect Your Forms Like a Pro: Anti-Spam Techniques That Actually Work

Before we dive in, it's important to know: most spammers use scripts, not humans. These bots scan for forms, autofill fields, and send POST requests rapidly—sometimes thousands per hour.

So your goal isn’t to annoy humans, it’s to trip up bots.

Apr 04, 2025
Read More
Tutorial
bash

Setting Correct Permissions for Laravel

Run the following commands to set ownership:

sudo chown -R www-data:www-data /path/to/your/laravel_project/storage
sudo chown -R www-data:www-data /path/to/your/laravel_project/bootstrap/cache

Nov 07, 2024
Read More
Tutorial
bash

Renaming a subdomain in Apache and generating a new SSL certificate

sudo certbot --apache -d new.example.com

This command will:

Nov 07, 2024
Read More
Tutorial

How To view tables and the number of records in each table in a PostgreSQL database,

Start by connecting to your database using:

   psql -U your_username -d your_database_name

Nov 06, 2024
Read More
Tutorial

How to install PostgreSQL

   sudo apt update
   sudo apt install postgresql postgresql-contrib

Nov 06, 2024
Read More
Tutorial

How to view tables on a PostgreSQL database hosted on Heroku

   heroku config:get DATABASE_URL -a <your-app-name>

This will display a URL in the format: postgres://<user>:<password>@<host>:<port>/<database>

Nov 06, 2024
Read More
Tutorial

How to view your Heroku Apps

Make sure you’re logged in to the Heroku CLI by running:

   heroku login

Nov 06, 2024
Read More
Cheatsheet

Essential dpkg Commands Cheat Sheet for Debian and Ubuntu Systems

  • Install a package:
  sudo dpkg -i package_name.deb

Oct 24, 2024
Read More
Tutorial

Getting Started with DevSecOps — Secure CI/CD Pipelines with Jenkins

After the security tests and scans are completed, it’s important to set up notifications in case of any issues.

Jenkins can be configured to send notifications when a pipeline fails. Go to Manage Jenkins > Configure System and set up an email server.

Oct 22, 2024
Read More
Tutorial
bash

How to Install and Configure Apache on Ubuntu

To customize the default website served by Apache, edit the configuration file:

sudo nano /etc/apache2/sites-available/000-default.conf

Oct 21, 2024
Read More
Tutorial
bash

How to Create SSL for a Website on Ubuntu

sudo apt install certbot python3-certbot-apache
sudo apt install certbot python3-certbot-nginx

Oct 21, 2024
Read More
Tutorial
bash

How to Install MongoDB Shell (mongosh) on Ubuntu

wget https://downloads.mongodb.com/compass/mongosh-1.10.1-linux-x64.tgz

Extract the contents of the downloaded file using the tar command:

Oct 18, 2024
Read More
Tutorial

How to Install MongoDB on Ubuntu

sudo apt-get update

To verify the integrity of the packages you download, MongoDB provides a GPG key. Add this key to your system by running the following command:

Oct 18, 2024
Read More
Cheatsheet

PM2 Cheatsheet

pm2 kill
pm2 uninstall pm2-logrotate

Oct 14, 2024
Read More
Tutorial
bash

How to Update Node.js and npm on Ubuntu

sudo apt remove nodejs

This command removes the old version of Node.js from your system.

Oct 03, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!