<div dir="ltr"><div>Newer versions of find have some more built in commands, in particular -delete.</div><div><br></div><div>Daily I run a script of mine that does a number of daily maintenance things.  One part in particular looks for any invalid .srt files (<a href="http://opensubtitles.org">opensubtitles.org</a> often sticks one line advertisements in a .srt instead of the actual subtitles).  So I run the following in my videos folders:</div><div><br></div><div>find /mnt/athenavids/ -type f -size -150c -iname &quot;*.srt&quot; -delete -print</div><div><br></div><div>What this does is look in my video folder for any files with the extension .srt less than 150 bytes (those advertisements are 102 bytes, usually), then it deletes them and prints the filename so I can watch to see where it&#39;s finding them.</div><div><br></div><div>That -delete part in particular used to be -exec rm {} \;   -- nice that they made it easier to use in the newer versions.  Running &quot;man find&quot; will list other neat tricks.</div><div><br></div><div><br></div><div><br></div><div><br></div><div><pre class="gmail-wp-block-code"><code><br><br></code></pre><br></div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Sat, 8 Nov 2025 at 03:47, Ron &lt;<a href="mailto:ron@bclug.ca">ron@bclug.ca</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Mikalai Birukou via kwlug-disc wrote on 2025-11-07 13:46:<br>
<br>
&gt; As a reminder, bash&#39;s find has option -exec, that let&#39;s you do<br>
&gt; something during find&#39;s iteration.<br>
That&#39;s one of my favourite options with `find`.<br>
<br>
<br>
It should be noted that `find ... -exec ...` requires a semi-colon at <br>
the end. But, that semi-colon needs to be escaped like this: \;<br>
<br>
<br>
Unless... one doesn&#39;t want the default behaviour of whatever is being <br>
exec&#39;d to run *once per found item*.<br>
<br>
If one would prefer everything found to be passed at once, finish the <br>
statement with \+<br>
<br>
<br>
Unless... there&#39;s a whole bunch of stuff being found, then it gets <br>
buffered and passed to the -exec&#39;d program when the buffer is full, not <br>
just when the `find` is done.<br>
<br>
<br>
How big is the buffer? Who knows, good luck.<br>
<br>
<br>
Someone wanted to find the newest or oldest file on a failing disk.<br>
<br>
I suggested something like:<br>
<br>
find $mount_point -type f -exec ls -lta {} \+ | head -n 1<br>
<br>
<br>
It worked perfectly on some test folders.<br>
<br>
One an entire disk though?  Too many entries returned, got sorted <br>
chunks, completely failed.<br>
<br>
I think the buffer consisted of about 300 entries, out of thousands.<br>
<br>
<br>
<br>
Anyway, there&#39;s a thread about &quot;find newest and oldest items on a disk&quot; <br>
with some of the craziest mailing list replies I&#39;ve ever seen (makes me <br>
rethink my skepticism about full moons) starting here:<br>
<br>
<a href="https://mail.ale.org/pipermail/ale/2025-April/166848.html" rel="noreferrer" target="_blank">https://mail.ale.org/pipermail/ale/2025-April/166848.html</a><br>
<br>
<br>
Staggeringly incorrect answers abound, to the point where it&#39;s fun to <br>
see &quot;what will they come up with next?&quot;<br>
<br>
<br>
<br>
My final answer:<br>
<br>
find $mount_point -printf &quot;%TY-%Tm-%Td %TH:%TM:%TS %p\0&quot;  \<br>
     | sort --zero-terminated \<br>
     | tr &#39;\0&#39; &#39;\n&#39;           \<br>
     | sed -n -e 1p -e &#39;$p&#39;<br>
<br>
Probably contains subtle errors still.<br>
<br>
<br>
_______________________________________________<br>
kwlug-disc mailing list<br>
To unsubscribe, send an email to <a href="mailto:kwlug-disc-leave@kwlug.org" target="_blank">kwlug-disc-leave@kwlug.org</a><br>
with the subject &quot;unsubscribe&quot;, or email<br>
<a href="mailto:kwlug-disc-owner@kwlug.org" target="_blank">kwlug-disc-owner@kwlug.org</a> to contact a human being.<br>
</blockquote></div>