{"id":2968,"date":"2020-04-01T08:12:46","date_gmt":"2020-04-01T08:12:46","guid":{"rendered":"https:\/\/chemicloud.com\/kb\/?post_type=ht_kb&#038;p=2968"},"modified":"2023-02-13T09:48:07","modified_gmt":"2023-02-13T09:48:07","slug":"find-remove-large-error_log-files","status":"publish","type":"ht_kb","link":"https:\/\/chemicloud.com\/kb\/article\/find-remove-large-error_log-files\/","title":{"rendered":"How to Find &#038; Remove Large error_log Files in Linux"},"content":{"rendered":"<p>In this tutorial, you will learn how to find and remove large error_log files generated by your scripts, while running from a Linux platform.<\/p>\n<h3 id=\"how-to-find-error_log-files-in-linux\">How to Find error_log Files in Linux<\/h3>\n<p>List the Error Log files with its disk space usage details:<\/p>\n<pre># find . -type f -iname error_log -exec du -sh {} \\;<\/pre>\n<ul>\n<li>type : Specify the type to find.<\/li>\n<li>iname: Specify the name to find.<\/li>\n<li>exec: Execute the \u201cdu -sch\u201d and lists the output with file size.<\/li>\n<\/ul>\n<h3 id=\"how-to-find-and-delete-error_log-files-in-linux\">How to Find and Delete error_log Files in Linux<\/h3>\n<pre># find . -type f -iname error_log -delete<\/pre>\n<ul>\n<li>delete: This switch removes the outputs from the find command.<\/li>\n<\/ul>\n<h3 id=\"how-to-find-all-the-error_log-files-larger-than-1-gb\">How to Find All the error_log Files Larger Than 1 GB<\/h3>\n<p>To find all the error_log files larger than 1 GB (1,073,741,824 bytes) in the current directory and its subdirectories, you can use the following command:<\/p>\n<pre>find . -<span class=\"hljs-built_in\">type<\/span> f -name <span class=\"hljs-string\">\"error_log\"<\/span> -size +1000000000c -<span class=\"hljs-built_in\">exec<\/span> <span class=\"hljs-built_in\">ls<\/span> -lh {} \\;<\/pre>\n<p>Explanation of the command options:<\/p>\n<ul>\n<li><code>find .<\/code>: start searching from the current directory (<code>.<\/code>)<\/li>\n<li><code>-type f<\/code>: only look for files (not directories)<\/li>\n<li><code>-name \"error_log\"<\/code>: only consider files with the name &#8220;error_log&#8221;<\/li>\n<li><code>-size +1000000000c<\/code>: only consider files that are larger than 1 GB (1,000,000,000 bytes)<\/li>\n<li><code>-exec ls -lh {} \\;<\/code>: run the <code>ls -lh<\/code> command on each file found, displaying its size in human-readable format. The <code>{}<\/code> placeholder is replaced with the path to each file, and the <code>\\;<\/code> is used to end the <code>exec<\/code> command.<\/li>\n<\/ul>\n<p>The <code>ls -lh<\/code> command displays information about the files, including their size, permissions, and modification date. The <code>-h<\/code> option makes the size human-readable, so it will show values like &#8220;1.0G&#8221; instead of &#8220;1000000000&#8221;.<\/p>\n<h3 id=\"how-to-find-and-remove-all-the-error_log-files-larger-than-1-gb\">How to Find and Remove All the error_log Files Larger Than 1 GB<\/h3>\n<pre>find . -<span class=\"hljs-built_in\">type<\/span> f -name <span class=\"hljs-string\">\"error_log\"<\/span> -size +1000000000c -<span class=\"hljs-built_in\">exec<\/span> <span class=\"hljs-built_in\">rm<\/span> {} \\;<\/pre>\n<div class=\"flex-1 overflow-hidden\">\n<div class=\"react-scroll-to-bottom--css-wrrre-79elbk h-full dark:bg-gray-800\">\n<div class=\"react-scroll-to-bottom--css-wrrre-1n7m0yu\">\n<div class=\"flex flex-col items-center text-sm dark:bg-gray-800\">\n<div class=\"w-full border-b border-black\/10 dark:border-gray-900\/50 text-gray-800 dark:text-gray-100 group bg-gray-50 dark:bg-[#444654]\">\n<div class=\"text-base gap-4 md:gap-6 m-auto md:max-w-2xl lg:max-w-2xl xl:max-w-3xl p-4 md:py-6 flex lg:px-0\">\n<div class=\"relative flex w-[calc(100%-50px)] flex-col gap-1 md:gap-3 lg:w-[calc(100%-115px)]\">\n<div class=\"flex flex-grow flex-col gap-3\">\n<div class=\"min-h-[20px] flex flex-col items-start gap-4 whitespace-pre-wrap\">\n<div class=\"markdown prose w-full break-words dark:prose-invert light\">\n<p>Explanation of the command options:<\/p>\n<ul>\n<li><code>find .<\/code>: start searching from the current directory (<code>.<\/code>)<\/li>\n<li><code>-type f<\/code>: only look for files (not directories)<\/li>\n<li><code>-name \"error_log\"<\/code>: only consider files with the name &#8220;error_log&#8221;<\/li>\n<li><code>-size +1000000000c<\/code>: only consider files that are larger than 1 GB (1,000,000,000 bytes)<\/li>\n<li><code>-exec rm {} \\;<\/code>: run the <code>rm<\/code> command on each file found, removing it from the file system. The <code>{}<\/code> placeholder is replaced with the path to each file, and the <code>\\;<\/code> is used to end the <code>exec<\/code> command.<\/li>\n<\/ul>\n<p>Note: The <code>rm<\/code> command permanently deletes files. Make sure you want to delete the files before running this command, as it does not send the files to the trash bin or provide any means to recover the deleted files.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p><b>Tired of hassling with website issues?<span class=\"Apple-converted-space\">\u00a0 <\/span>ChemiCloud is the managed hosting solution designed to save you time and money! <\/b>\ud83e\udd13<b> Check out our <\/b><span style=\"text-decoration: underline;\"><a href=\"https:\/\/chemicloud.com\/pricing#60b65e4e63b58\" target=\"_blank\" rel=\"noopener\"><span class=\"s1\"><b>web hosting <\/b><\/span><\/a><\/span><b>plans!<\/b><\/p>\n<h3 id=\"how-to-find-and-delete-error_log-files-using-a-cron-job\">How to Find and Delete error_log Files using a Cron job<\/h3>\n<p>If you want to automatically remove all the error_log files which are being generated, you can achieve this by setting up a <a href=\"https:\/\/chemicloud.com\/kb\/article\/setup-manage-cron-jobs\/\" target=\"_blank\" rel=\"noopener noreferrer\">cron job<\/a>.<\/p>\n<p>The command that the cron job should execute is:<\/p>\n<pre>\/bin\/find \/home\/user -type f -iname error_log -delete<\/pre>\n<p>Example: 0 * * * * \/bin\/find \/home\/eatat\/ -type f -iname error_log -delete<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you will learn how to find and remove large error_log files generated by your scripts, while running from a Linux platform. How to Find error_log Files in Linux List the Error Log files with its disk space usage details: # find . -type f -iname error_log -exec&#8230;<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"ht-kb-category":[188],"ht-kb-tag":[],"class_list":["post-2968","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-support-resources"],"_links":{"self":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb\/2968","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/comments?post=2968"}],"version-history":[{"count":6,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb\/2968\/revisions"}],"predecessor-version":[{"id":7794,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb\/2968\/revisions\/7794"}],"wp:attachment":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/media?parent=2968"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb-category?post=2968"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb-tag?post=2968"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}