Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Disk Cleanup Script

A Python utility script for monitoring and cleaning up disk space on Linux systems. This script identifies directories with high disk usage and helps remove old files to free up space.

Features

  • Disk Space Monitoring: Displays current disk usage for all mounted filesystems
  • Automatic Detection: Identifies directories with 100% disk usage
  • Smart Cleanup: Removes files older than 30 days
  • Interactive Mode: Prompts for confirmation before deleting files
  • Manual Mode: Allows cleaning specific directories manually
  • Safety Checks: Verifies write permissions before attempting deletions

Requirements

  • Python 3.x
  • Linux/Unix system with df command
  • Write permissions for directories you want to clean

Usage

  1. Make the script executable:

    chmod +x disk_cleanup.py
  2. Run the script:

    ./disk_cleanup.py

    or

    python3 disk_cleanup.py

How It Works

  1. Initial Scan: The script displays current disk space information using the df -h command
  2. Identify Full Directories: Automatically detects filesystems with 100% usage
  3. Cleaning Options:
    • Automatic Mode: Automatically processes all full directories
    • Manual Mode: Allows you to specify which directory to clean
  4. File Deletion: Removes files older than 30 days (files not modified in the last 30 days)
  5. Confirmation: Always asks for confirmation before deleting files
  6. Final Report: Shows disk space after cleanup

Safety Features

  • Confirmation Prompts: Requires user confirmation before deleting files
  • Permission Checks: Verifies write access before attempting deletions
  • Error Handling: Gracefully handles file not found errors and permission issues
  • File Age Filter: Only targets files older than 30 days

Example Output

Disk space before cleanup:
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        20G   20G     0 100% /
...

Directories with high disk usage:
/: 100.0%

Do you want to automatically clean the full directories? (y/n): y

Notes

  • The script deletes files based on modification time (mtime)
  • Files older than 30 days are considered for deletion
  • The script will not delete files if the directory is read-only
  • Always review the list of files marked for deletion before confirming

License

This script is provided as-is for personal use.

About

Disk cleanup utility tool for Linux. Helps clean temporary files, cache, and free up disk space.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages