<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: easiest way to remove hadoop logs in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/easiest-way-to-remove-hadoop-logs/m-p/125259#M47327</link>
    <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/11016/avijeetd.html" nodeid="11016"&gt;@Avijeet Dash&lt;/A&gt;, The suggestion from Sunile is great. But, where you can't do that, here is a solution.&lt;/P&gt;&lt;P&gt;If you need to manually delete all but the last X files named with a certain file pattern (*.zip, files*.log, etc), you can run something like this command which finds all but the most recent 5 matching files.&lt;/P&gt;&lt;P&gt;&lt;EM&gt;
&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;# find &lt;STRONG&gt;MY_LOG_DIR&lt;/STRONG&gt; -type f -name &lt;STRONG&gt;"FILE_PATTERN&lt;/STRONG&gt;&lt;STRONG&gt;"&lt;/STRONG&gt; -printf "%T+\t%p\n" | sort |awk '{print $2}' |head -n &lt;STRONG&gt;-5 &lt;/STRONG&gt;|xargs -i &lt;STRONG&gt;CMD_FOR_EACH_FILE&lt;/STRONG&gt; {}&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Replace the bold parts as needed.&lt;/P&gt;&lt;P&gt;For example, the following command will find all but the most recent 5 files matching pattern *.log.20##-##-## and deletes them. Note, since this command is a delete command, before running something so drastic, you should test first by replacing the "rm" with "ls -l" or do a "mv" instead. Test, test, test.&lt;/P&gt;&lt;P&gt;&lt;EM&gt;# find &lt;STRONG&gt;/var/log/hive&lt;/STRONG&gt; -type f -name &lt;STRONG&gt;"*.log.20[0-9][0-9]-[0-2][0-9]-[0-9][0-9]&lt;/STRONG&gt;&lt;STRONG&gt;"&lt;/STRONG&gt; -printf "%T+\t%p\n" | sort |awk '{print $2}' |head -n -5 |xargs -i &lt;STRONG&gt;rm &lt;/STRONG&gt;{}&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;There are always many ways to solve a problem and I'm sure there is a more elegant solution.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Nov 2016 02:13:04 GMT</pubDate>
    <dc:creator>james_jones</dc:creator>
    <dc:date>2016-11-29T02:13:04Z</dc:date>
    <item>
      <title>easiest way to remove hadoop logs</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/easiest-way-to-remove-hadoop-logs/m-p/125257#M47325</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Can I just delete rm -rf  * from some of the log folders such as /var/log/hive&lt;/P&gt;&lt;P&gt;16G     ./hive&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Avijeet&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 10:49:49 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/easiest-way-to-remove-hadoop-logs/m-p/125257#M47325</guid>
      <dc:creator>avijeetd</dc:creator>
      <dc:date>2022-09-16T10:49:49Z</dc:date>
    </item>
    <item>
      <title>Re: easiest way to remove hadoop logs</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/easiest-way-to-remove-hadoop-logs/m-p/125258#M47326</link>
      <description>&lt;P&gt;You can remove the log files but I would recommend much easier way to have this automated.&lt;/P&gt;&lt;P&gt;Most services in hadoop user log4j.  Simply enable RollingFileAppender and set MaxBackupIndex to max number of log files you want to retention for that service.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.hortonworks.com/articles/48937/how-do-i-control-log-file-retention-for-common-hdp.html" target="_blank"&gt;https://community.hortonworks.com/articles/48937/how-do-i-control-log-file-retention-for-common-hdp.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2016 00:22:57 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/easiest-way-to-remove-hadoop-logs/m-p/125258#M47326</guid>
      <dc:creator>sunile_manjee</dc:creator>
      <dc:date>2016-11-29T00:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: easiest way to remove hadoop logs</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/easiest-way-to-remove-hadoop-logs/m-p/125259#M47327</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/11016/avijeetd.html" nodeid="11016"&gt;@Avijeet Dash&lt;/A&gt;, The suggestion from Sunile is great. But, where you can't do that, here is a solution.&lt;/P&gt;&lt;P&gt;If you need to manually delete all but the last X files named with a certain file pattern (*.zip, files*.log, etc), you can run something like this command which finds all but the most recent 5 matching files.&lt;/P&gt;&lt;P&gt;&lt;EM&gt;
&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;# find &lt;STRONG&gt;MY_LOG_DIR&lt;/STRONG&gt; -type f -name &lt;STRONG&gt;"FILE_PATTERN&lt;/STRONG&gt;&lt;STRONG&gt;"&lt;/STRONG&gt; -printf "%T+\t%p\n" | sort |awk '{print $2}' |head -n &lt;STRONG&gt;-5 &lt;/STRONG&gt;|xargs -i &lt;STRONG&gt;CMD_FOR_EACH_FILE&lt;/STRONG&gt; {}&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Replace the bold parts as needed.&lt;/P&gt;&lt;P&gt;For example, the following command will find all but the most recent 5 files matching pattern *.log.20##-##-## and deletes them. Note, since this command is a delete command, before running something so drastic, you should test first by replacing the "rm" with "ls -l" or do a "mv" instead. Test, test, test.&lt;/P&gt;&lt;P&gt;&lt;EM&gt;# find &lt;STRONG&gt;/var/log/hive&lt;/STRONG&gt; -type f -name &lt;STRONG&gt;"*.log.20[0-9][0-9]-[0-2][0-9]-[0-9][0-9]&lt;/STRONG&gt;&lt;STRONG&gt;"&lt;/STRONG&gt; -printf "%T+\t%p\n" | sort |awk '{print $2}' |head -n -5 |xargs -i &lt;STRONG&gt;rm &lt;/STRONG&gt;{}&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;There are always many ways to solve a problem and I'm sure there is a more elegant solution.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2016 02:13:04 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/easiest-way-to-remove-hadoop-logs/m-p/125259#M47327</guid>
      <dc:creator>james_jones</dc:creator>
      <dc:date>2016-11-29T02:13:04Z</dc:date>
    </item>
    <item>
      <title>Re: easiest way to remove hadoop logs</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/easiest-way-to-remove-hadoop-logs/m-p/125260#M47328</link>
      <description>&lt;P&gt;Note that the above is deletes older files based on file modification time, not based on the timestamp in the filename. I did use the filename with a timestamp, which probably makes the example confusing. So that command could be used with any kind of file such as keeping the last 5 copies of your backup files.&lt;/P&gt;&lt;P&gt;Also, if you use &lt;STRONG&gt;logrotate &lt;/STRONG&gt;(e.g. where log4j rolling files is not an option), you can use the &lt;STRONG&gt;maxage&lt;/STRONG&gt; option, which also uses modified time. This is from the logrotate man page:&lt;/P&gt;&lt;PRE&gt;       maxage count
              Remove  rotated logs older than &amp;lt;count&amp;gt; days. The age is only checked if the logfile is to be rotated. The files are mailed to the configured address if maillast and mail are configured.&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Nov 2016 02:26:27 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/easiest-way-to-remove-hadoop-logs/m-p/125260#M47328</guid>
      <dc:creator>james_jones</dc:creator>
      <dc:date>2016-11-29T02:26:27Z</dc:date>
    </item>
  </channel>
</rss>

