{"id":5878,"date":"2024-11-27T19:41:05","date_gmt":"2024-11-27T14:11:05","guid":{"rendered":"https:\/\/www.veeble.com\/kb\/?p=5878"},"modified":"2025-03-06T11:27:42","modified_gmt":"2025-03-06T05:57:42","slug":"how-to-clean-your-ubuntu-server","status":"publish","type":"post","link":"https:\/\/www.veeble.com\/kb\/how-to-clean-your-ubuntu-server\/","title":{"rendered":"How To Clean Your Ubuntu Server"},"content":{"rendered":"\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/11\/Clean-your-Ubuntu-Servers.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"537\" src=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/11\/Clean-your-Ubuntu-Servers-1024x537.jpg\" alt=\"How To Clean Your Ubuntu Server\" class=\"wp-image-5905\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/11\/Clean-your-Ubuntu-Servers-1024x537.jpg 1024w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/11\/Clean-your-Ubuntu-Servers-300x157.jpg 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/11\/Clean-your-Ubuntu-Servers-768x402.jpg 768w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/11\/Clean-your-Ubuntu-Servers.jpg 1080w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>Maintaining a clean <a href=\"https:\/\/ubuntu.com\/\" target=\"_blank\" rel=\"noopener\">Ubuntu server<\/a> ensures better performance, optimal storage usage, and a healthy operating environment. Over time, servers accumulate unnecessary files, unused packages, logs, and other redundant data. Regular cleaning can prevent disk space issues and enhance system efficiency.<\/p>\n\n\n\n<p>Ubuntu servers, like any other system, can become cluttered with old logs, temporary files, and unused software. Regular maintenance ensures the system remains stable, secure, and efficient. In this article, we\u2019ll explore various commands and tools to clean your Ubuntu server safely and effectively.<\/p>\n\n\n\n<p>Maintaining sufficient disk space is a challenge many system administrators face today. With <a href=\"https:\/\/www.veeble.com\/in\/vps-hosting\/\">servers <\/a>handling large volumes of data and numerous applications, it\u2019s easy for storage to fill up unexpectedly. However, regular cleanup can effectively resolve this issue, ensuring better performance and stability for your Ubuntu server. Log files, temporary files, unused packages, and outdated data can quickly pile up on your Ubuntu server. Left unchecked, this can lead to reduced performance and even server crashes. By implementing the cleanup steps outlined in this article, you can proactively manage disk space and prevent issues.<\/p>\n\n\n\t\t\t\t<div class=\"wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-d1f457e5      \"\n\t\t\t\t\tdata-scroll= \"1\"\n\t\t\t\t\tdata-offset= \"30\"\n\t\t\t\t\tstyle=\"\"\n\t\t\t\t>\n\t\t\t\t<div class=\"uagb-toc__wrap\">\n\t\t\t\t\t\t<div class=\"uagb-toc__title\">\n\t\t\t\t\t\t\tTable Of Contents\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div class=\"uagb-toc__list-wrap \">\n\t\t\t\t\t\t<ol class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#prerequisites\" class=\"uagb-toc-link__trigger\">Prerequisites<\/a><li class=\"uagb-toc__list\"><a href=\"#different-methods-to-clean-an-ubuntu-server\" class=\"uagb-toc-link__trigger\">Different Methods to Clean an Ubuntu Server<\/a><ul class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#remove-unnecessary-packages\" class=\"uagb-toc-link__trigger\">Remove Unnecessary Packages<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#clear-log-files\" class=\"uagb-toc-link__trigger\">Clear Log Files<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#remove-old-kernels\" class=\"uagb-toc-link__trigger\">Remove Old Kernels<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#clean-temporary-files\" class=\"uagb-toc-link__trigger\">Clean Temporary Files<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#clear-unused-snaps\" class=\"uagb-toc-link__trigger\">Clear Unused Snaps<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#clear-thumbnail-cache\" class=\"uagb-toc-link__trigger\">Clear Thumbnail cache<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#remove-unused-applications\" class=\"uagb-toc-link__trigger\">Remove Unused Applications<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#clean-package-cache\" class=\"uagb-toc-link__trigger\">Clean Package Cache<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#analyze-disk-usage-and-remove-large-files-if-not-required\" class=\"uagb-toc-link__trigger\">Analyze Disk Usage and Remove Large Files if not required<\/a><\/li><\/ul><\/li><li class=\"uagb-toc__list\"><a href=\"#conclusion\" class=\"uagb-toc-link__trigger\">Conclusion<\/a><ul class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#get-your-website-online-today\" class=\"uagb-toc-link__trigger\">Get Your Website Online Today!<\/a><\/ul><\/ul><\/ol>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\n\n<h2 class=\"wp-block-heading\" id=\"prerequisites\"><strong>Prerequisites<\/strong><\/h2>\n\n\n<ul class=\"wp-block-list\">\n<li>You have <strong>sudo privileges<\/strong> on the server.<\/li>\n\n\n\n<li>A <strong>backup of critical files and configurations<\/strong> is taken to avoid accidental data loss.<\/li>\n\n\n\n<li>Basic knowledge of Linux commands.<\/li>\n<\/ul>\n\n\n<h2 class=\"wp-block-heading\" id=\"different-methods-to-clean-an-ubuntu-server\"><strong>Different Methods to Clean an Ubuntu Server<\/strong><\/h2>\n\n<h3 class=\"wp-block-heading\" id=\"remove-unnecessary-packages\"><strong>Remove Unnecessary Packages<\/strong><\/h3>\n\n\n<p>Unnecessary packages, including residual dependencies, can occupy disk space on your Ubuntu server. You can remove them using the following commands,<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt autoremove -y<\/code><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id=\"clear-log-files\">Clear Log Files<\/h3>\n\n\n<p>Log files can accumulate over time, consuming significant disk space on your Ubuntu server.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>du -sh \/var\/log\/*      \/\/Check the size of log files\n\njournalctl --vacuum-time=1week   \/\/remove all log files older than one weeks.<\/code><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id=\"remove-old-kernels\">Remove Old Kernels<\/h3>\n\n\n<p>As your Ubuntu server updates to newer kernel versions, older kernels remain installed to allow fallback in case of issues. However, over time, these outdated kernels can consume significant disk space, especially on servers with limited storage. Removing these old kernels helps optimize disk usage without affecting the server&#8217;s functionality.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt-get autoremove --purge -y<\/code><\/pre>\n\n\n\n<p>This command ensures only the current kernel and its dependencies are kept while clearing outdated ones.<\/p>\n\n\n<h3 class=\"wp-block-heading\" id=\"clean-temporary-files\">Clean Temporary Files<\/h3>\n\n\n<p>Temporary files are created by various processes, including application installations, user sessions, and system operations. Over time, these files can accumulate and consume valuable disk space on your Ubuntu server. Cleaning temporary files helps optimize performance and free up storage.<br>The <code>\/tmp<\/code> directory stores temporary files created by the system and applications. These files are usually safe to delete.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rm -rf \/tmp\/*<\/code><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id=\"clear-unused-snaps\"><strong>Clear Unused Snaps<\/strong><\/h3>\n\n\n<p>Snap automatically keeps the current and previous versions of installed packages. You can remove all unused versions using the following command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>snap remove &lt;snap_name&gt; --revision &lt;revision_number&gt;<\/code><\/pre>\n\n\n\n<p>Replace <code>&lt;snap-name&gt;<\/code> with the name of the snap and <code>&lt;old-revision-number&gt;<\/code> with the version number you want to remove. You can also use the <code>--purge<\/code> option to ensure complete removal.<\/p>\n\n\n<h3 class=\"wp-block-heading\" id=\"clear-thumbnail-cache\">Clear Thumbnail cache<\/h3>\n\n\n<p>Linux distributions generate thumbnail images for files such as images, videos, and documents to provide a quicker preview when browsing directories. While this improves usability, over time, the thumbnail cache can grow large and consume unnecessary disk space. Clearing the thumbnail cache is a simple way to recover some space without causing any issues to your system.<\/p>\n\n\n\n<p>The thumbnail cache is usually stored in the <code>~\/.cache\/thumbnails\/<\/code> directory. You can manually delete it with the following command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rm -rf ~\/.cache\/thumbnails\/*<\/code><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id=\"remove-unused-applications\"><strong>Remove Unused Applications<\/strong><\/h3>\n\n\n<p>Over time, you may accumulate unused applications on your system that take up valuable disk space and may even slow down your system. Removing these unnecessary applications not only frees up storage but can also help improve overall system performance.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt-get remove --purge &lt;application_name&gt;<\/code><\/pre>\n\n\n\n<p>The <code>--purge<\/code> option ensures that configuration files related to the application are also removed.<\/p>\n\n\n<h3 class=\"wp-block-heading\" id=\"clean-package-cache\"><strong>Clean Package Cache<\/strong><\/h3>\n\n\n<p>Over time, the package manager on Ubuntu (APT) accumulates cached packages when you install or update software. This cache is stored in the <code>\/var\/cache\/apt\/archives<\/code> directory, and while it allows for quick reinstallation of packages, it can take up a considerable amount of space, especially if you install and update many packages.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt-get clean<\/code><\/pre>\n\n\n\n<p>This command removes all the <code>.deb<\/code> package files from the cache that were downloaded during installations or updates. It doesn\u2019t affect the installed packages, but it frees up space taken by the cached files.<\/p>\n\n\n<h3 class=\"wp-block-heading\" id=\"analyze-disk-usage-and-remove-large-files-if-not-required\">Analyze Disk Usage and Remove Large Files if not required<\/h3>\n\n\n<p>If you\u2019re running low on disk space on your Ubuntu server, analyzing disk usage and removing large files that are no longer needed is a critical step. Here\u2019s how to efficiently identify large files and free up disk space.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>du -sh \/path\/to\/directory<\/code><\/pre>\n\n\n\n<p>Also, to see a detailed list of all files and directories in the current directory, sorted by size use the below command. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>du -ah \/path\/to\/directory | sort -rh | head -n 20<\/code><\/pre>\n\n\n\n<p>This command will display the top 20 largest files and directories.<\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n<p>The struggle to manage disk space on servers is real, but it is a problem that can be effectively addressed with regular maintenance. By following these steps, you can reclaim valuable storage, improve performance, and keep your Ubuntu server running smoothly. Stay proactive in managing disk space, as a clean server is the foundation of a reliable and efficient system. Always remember to back up important data before initiating cleanup processes to safeguard against accidental losses.<\/p>\n\n\n\n<div style=\"height:35px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-uagb-call-to-action uagb-block-aa7664db wp-block-button\"><div class=\"uagb-cta__wrap\"><h3 class=\"uagb-cta__title\">Get Your Website Online Today!<\/h3><p class=\"uagb-cta__desc\">Veeble&#8217;s cPanel hosting is the perfect solution for businesses and individuals who want to create a professional website.<\/p><\/div><div class=\"uagb-cta__buttons\"><a href=\"https:\/\/www.veeble.com\/in\/cpanel-hosting\/\" class=\"uagb-cta__button-link-wrapper wp-block-button__link\" target=\"_blank\" rel=\"noopener noreferrer\">Get Started Today!<svg xmlns=\"https:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\"><path d=\"M504.3 273.6l-112.1 104c-6.992 6.484-17.18 8.218-25.94 4.406c-8.758-3.812-14.42-12.45-14.42-21.1L351.9 288H32C14.33 288 .0002 273.7 .0002 255.1S14.33 224 32 224h319.9l0-72c0-9.547 5.66-18.19 14.42-22c8.754-3.809 18.95-2.075 25.94 4.41l112.1 104C514.6 247.9 514.6 264.1 504.3 273.6z\"><\/path><\/svg><\/a><\/div><\/div>\n\n\n\n<div style=\"height:35px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-ast-global-color-8-color has-text-color has-link-color wp-elements-22d3202bc96c2fac8611f39aeda01b57\"><strong>Also Reads:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-veeble-hosting wp-block-embed-veeble-hosting\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"yxr8gmrvVw\"><a href=\"https:\/\/www.veeble.com\/kb\/how-to-set-up-ufw-firewall-on-ubuntu\/\">How to Set Up UFW Firewall on Ubuntu<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;How to Set Up UFW Firewall on Ubuntu&#8221; &#8212; Veeble Hosting\" src=\"https:\/\/www.veeble.com\/kb\/how-to-set-up-ufw-firewall-on-ubuntu\/embed\/#?secret=SDpbWG8CDQ#?secret=yxr8gmrvVw\" data-secret=\"yxr8gmrvVw\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-veeble-hosting wp-block-embed-veeble-hosting\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"27WdTcCHQF\"><a href=\"https:\/\/www.veeble.com\/kb\/how-to-fix-e-unable-to-locate-package-error-on-ubuntu\/\">How to Fix \u201cE: Unable to Locate Package\u201d Error on Ubuntu<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;How to Fix \u201cE: Unable to Locate Package\u201d Error on Ubuntu&#8221; &#8212; Veeble Hosting\" src=\"https:\/\/www.veeble.com\/kb\/how-to-fix-e-unable-to-locate-package-error-on-ubuntu\/embed\/#?secret=TnxKYSx4H5#?secret=27WdTcCHQF\" data-secret=\"27WdTcCHQF\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Maintaining a clean Ubuntu server ensures better performance, optimal storage usage, and a healthy operating environment. Over time, servers accumulate unnecessary files, unused packages, [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":7686,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[5],"tags":[],"class_list":["post-5878","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"uagb_featured_image_src":{"full":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/11\/How-To-Clean-Your-Ubuntu-Server.jpg",1366,768,false],"thumbnail":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/11\/How-To-Clean-Your-Ubuntu-Server-150x150.jpg",150,150,true],"medium":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/11\/How-To-Clean-Your-Ubuntu-Server-300x169.jpg",300,169,true],"medium_large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/11\/How-To-Clean-Your-Ubuntu-Server-768x432.jpg",768,432,true],"large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/11\/How-To-Clean-Your-Ubuntu-Server-1024x576.jpg",1024,576,true],"1536x1536":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/11\/How-To-Clean-Your-Ubuntu-Server.jpg",1366,768,false],"2048x2048":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/11\/How-To-Clean-Your-Ubuntu-Server.jpg",1366,768,false]},"uagb_author_info":{"display_name":"Nayana Nair","author_link":"https:\/\/www.veeble.com\/kb\/author\/nayana\/"},"uagb_comment_info":0,"uagb_excerpt":"Maintaining a clean Ubuntu server ensures better performance, optimal storage usage, and a healthy operating environment. Over time, servers accumulate unnecessary files, unused packages, [&hellip;]","_links":{"self":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/5878","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/comments?post=5878"}],"version-history":[{"count":9,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/5878\/revisions"}],"predecessor-version":[{"id":7815,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/5878\/revisions\/7815"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media\/7686"}],"wp:attachment":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media?parent=5878"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/categories?post=5878"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/tags?post=5878"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}