This content originally appeared on DEV Community and was authored by lithoeme
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>
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.
This content originally appeared on DEV Community and was authored by lithoeme

lithoeme | Sciencx (2025-01-05T23:14:47+00:00) Clean Your Linux Device. Retrieved from https://www.scien.cx/2025/01/05/clean-your-linux-device/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.