DEV Community

lithoeme
lithoeme

Posted on

1

Clean Your Linux Device

Use these commands to clean your linux device and get back to what it is you like to do. (Unless you like to clean linux systems; then please drop a comment below :D)

1. Remove Unnecessary Packages

Use the following commands to remove unused packages and their dependencies:

  • Remove packages that are no longer required:

     sudo apt autoremove
    
  • Remove unused packages and old dependencies (on Debian-based systems):

     sudo apt-get clean
     sudo apt-get autoclean
    
  • Clean up package cache:

     sudo apt-get clean
    

2. Clear System Logs

System logs can consume significant space. You can truncate or delete logs:

  • Clear the journal logs (on systemd systems):

     sudo journalctl --vacuum-size=100M
    
  • Clear old log files:

     sudo rm -rf /var/log/*
    

3. Delete Unused Temporary Files

Clean up temporary files that are no longer needed:

  • Use tmpwatch (if installed) to clean temporary files in /tmp:

     sudo tmpwatch --mtime 24 /tmp
    
  • Alternatively, clear /tmp manually:

     sudo rm -rf /tmp/*
    

4. Find and Remove Large Files

Use the find command to locate and delete large files that are taking up space:

  • List files larger than 1GB:

     sudo find / -type f -size +1G
    
  • Delete files over a specific size:

     sudo find /path/to/folder -type f -size +500M -exec rm -f {} \;
    

5. Clean Package Cache

If you've installed and updated many packages, cached files can build up over time:

  • Clean package manager cache (for apt):

     sudo apt-get clean
    
  • For dnf (on Fedora/RHEL-based systems):

     sudo dnf clean all
    

6. Check for Large Directories

Use du to find large directories and identify where space is being used:

  • Check the largest directories in your home folder:

     du -h --max-depth=1 ~/
    

7. Remove Old Snapshots (if using LVM or Snap)

If you're using LVM, delete old snapshots:

  • List LVM snapshots:

     sudo lvs
    
  • Remove a snapshot:

     sudo lvremove /dev/mapper/your-snapshot
    

If using snap, clean up unused snap versions:

   sudo snap list --all
   sudo snap remove <snap-name> --revision=<revision-number>
Enter fullscreen mode Exit fullscreen mode

8. Check for Orphaned Packages (Optional)

Use tools like deborphan to find and remove orphaned libraries:

  • Install deborphan:

     sudo apt install deborphan
    
  • List orphaned libraries:

     deborphan
    
  • Remove orphaned libraries:

     sudo apt-get remove --purge $(deborphan)
    

By following these steps, you can clean up unnecessary files and open up space on your Linux device.

edit: tmpwatch deprecated.

Billboard image

Imagine monitoring that's actually built for developers

Join Vercel, CrowdStrike, and thousands of other teams that trust Checkly to streamline monitor creation and configuration with Monitoring as Code.

Start Monitoring

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay