• Contact
  • About Me
  • Privacy Policy
DefenceDev
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos
No Result
View All Result
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos
No Result
View All Result
DefenceDev
No Result
View All Result
ADVERTISEMENT
Home Solutions

Solutions: Find and Delete Log Data or Any Files Older Than 30 Days on Linux

neo by neo
May 27, 2025
in Solutions
0
Solutions: Find and Delete Log Data or Any Files Older Than 30 Days on Linux

Solutions: Find and Delete Log Data or Any Files Older Than 30 Days on Linux

0
SHARES
14
VIEWS
Share on FacebookShare on Twitter
ADVERTISEMENT

Find and Delete Log Files on Linux

Find and Delete Log Data or Any Files Older Than 30 Days (or any period of time) on Linux is very important for system maintenance. Over time, log files and other data on a Linux system can accumulate, consuming valuable disk space and potentially affecting performance. In many cases, these files are no longer needed once they’ve surpassed a certain age. Cleaning up outdated files is essential to maintaining a smooth and efficient system.

Introduction

Managing log files is a critical aspect of maintaining a healthy and efficient system. As logs accumulate over time, they can consume valuable disk space and make it difficult to access recent or relevant information (they can crash the server or application if there is no space left on the hard drive). For system administrators and developers, the ability to automatically manage and clean up old log files is essential for ensuring system performance and reliability.

In this guide, we’ll explore practical solutions to list and delete log data that is older than 30 days. Whether you are working with Linux servers or local development machines, these methods will help streamline your log management process while minimizing manual intervention.

Let’s dive into some easy and effective techniques for tidying up your log directories!

Ubuntu Log Management

Ubuntu logs provide invaluable insights into the health, performance, and security of your system. They offer a detailed record of system events, errors, warnings, and user activities, enabling efficient troubleshooting, monitoring, and analysis.

ADVERTISEMENT

Key points related to Ubuntu logging:

  1. System Logs: Ubuntu maintains various system logs, including syslog, kernel logs (kern.log), authentication logs (auth.log), and others. These logs capture a wide range of system-level events, such as startup/shutdown sequences, hardware errors, and network activities.
  2. Application Logs: Applications running on Ubuntu often generate their own logs, typically stored in the /var/log directory. These logs provide insights into application-specific events, errors, and performance metrics, aiding in diagnosing issues and optimizing application behavior.
  3. Security Logs: Security logs, such as the auth.log and syslog, play a critical role in monitoring system security. They record authentication attempts, privilege escalations, and other security-related events, helping administrators detect and respond to potential security threats.
  4. Importance of Log Rotation: Ubuntu employs log rotation mechanisms to manage log files efficiently and prevent them from consuming excessive disk space. Log rotation involves archiving old logs, compressing them, and deleting outdated entries to maintain log file integrity and optimize storage usage.
  5. Log Monitoring and Analysis: Implementing log monitoring and analysis tools, such as Logwatch, Logstash, or Splunk, can streamline log management processes and facilitate proactive detection of anomalies, performance issues, and security breaches.

Find Files in the Specific Folder Older than 30 Days

This command lists all files in the /usr/local/vpnserver/packet_log/ directory that have not been modified for more than 30 days:

find /usr/local/vpnserver/packet_log/ -type f -mtime +30

Command Explanation

  1. find
    This is a powerful Linux command used to search for files and directories based on various criteria.
  2. /usr/local/vpnserver/packet_log/
    This specifies the directory where the find command will begin its search. In this case, it’s looking in the packet_log directory, which might contain log files from a VPN server.
  3. -type f
    This restricts the search to only files (f stands for “file”). Directories or other types of entries are excluded.
  4. -mtime +30
    This specifies that the find command should target files with a modification time of more than 30 days ago.
    • +30 means “older than 30 days.”
    • The modification time (mtime) is the last time the file’s contents were changed.
    • Note: If you wanted files modified exactly 30 days ago, you would use 30 (no + or -). For files modified in the last 30 days, use -30.

Save the Command Output in the File

To find all files in the /usr/local/vpnserver/packet_log/ directory that were last modified more than 30 days ago and appends their names to the file /home/user/deleted_files.log, creating the file if it does not already exist you can execute the following command:

ADVERTISEMENT
find /usr/local/vpnserver/packet_log/ -type f -mtime +30 >> /home/user/deleted_files.log

Delete Files Older than 30 Days

If you’d like to delete the files older than 30 days in the /usr/local/vpnserver/packet_log/ directory, use this command to find and remove them automatically:

ADVERTISEMENT
-- Delete logs
find /usr/local/vpnserver/packet_log/ -type f -mtime +30 -delete

defencedev.com

About The Author

neo

See author's posts

ADVERTISEMENT
Previous Post

Solutions: Run Command in Background on Ubuntu

Next Post

Solutions: Repeat Command in Ubuntu Terminal

neo

neo

Next Post
Solutions: Repeat Command in Ubuntu Terminal

Solutions: Repeat Command in Ubuntu Terminal

Follow Us

  • Trending
  • Comments
  • Latest
MikroTik: Export Configuration in Text File

MikroTik: Export Configuration in Text File

Fortinet FortiGate: Static Route Configuration via GUI and CLI

Fortinet FortiGate: Static Route Configuration via GUI and CLI

Immich: Installation on Ubuntu 22.04

Immich: Installation on Ubuntu 22.04

Fortinet FortiGate Upgrade Path Tool

Fortinet FortiGate Upgrade Path Tool

NextCloud: Port Forwarding - Essential Ports for Smooth Functionality

NextCloud: Port Forwarding – Essential Ports for Smooth Functionality and Remote Access

Organizing and Managing Photos with Immich: Features I Use

Organizing and Managing Photos with Immich: Features I Use

Install Ubuntu 22.04 on Oracle VM Virtual Box

Install Ubuntu 22.04 on Oracle VM Virtual Box

Linux Directories: cd (Change Directory), pwd (Print Working Directory), mkdir (Make Directory)

Linux Directories: cd (Change Directory), pwd (Print Working Directory), mkdir (Make Directory)

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

Recent News

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

MikroTik: Check Your Wireless Password

MikroTik: Check Your Wireless Password

ADVERTISEMENT

DefenceDev Tutorials

defencedev Logo

Whether you’re just starting or looking to expand your skills, I hope you find useful information and engaging discussions here. Let me take you through my journey and the goals behind this space!

Follow Us

Browse by Category

  • Blog
  • Cloud
    • Private
  • Linux Tutorials
    • Bash Scripting Tutorials
    • Commands
    • Networking
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Solutions
    • Docker
  • Video Tutorials
    • MikroTik Videos

Recent News

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

  • Site Map
  • Privacy Policy
  • Facebook Page
  • Disclaimer
  • Contact
  • About Me

© 2025 defencedev.com - All rights reserved.

No Result
View All Result
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos

© 2025 defencedev.com - All rights reserved.