To delete files in the /tmp
folder in Ubuntu, you can use the following commands:
1. Delete all files and folders:
sudo rm -rf /tmp/*
This command repeatedly (repeated) and without confirmation ( force) removes it.
Buy a high-quality virtual server at an economical price from Radib, Click now
2. Delete files older than a specified time (for example, 7 days):
sudo find /tmp -type f -mtime +7 -exec rm -f {} \;
This command only deletes files that are more than 7 days old since they were last created or modified.
3. Delete specific files (e.g. with log extension):
sudo rm -f /tmp/*.log
This command deletes files with the extension .log
.
Important points:
- Note: The
/tmp
folder usually contains temporary system files and programs. Incorrect removal may cause system or performance problems. - Automatic cleanup: Ubuntu automatically cleans up old temporary files when the system restarts. If your system has not been rebooted for a while, you may need to perform a manual cleanup.
- For added safety, you can check the contents before deleting the files using the following command:
ls -lh /tmp
Thanks for being with Radib in this tutorial.