Gods of Linux, how is it that there are only 80,000 songs in this folder, but find is returning 199,418?
>for i in {0..50}; do find ~/songs/ -iname "*.mp3" -o -iname "*.ogg" -typ
e f -mtime $i | wc -l; done | awk '{ sum += $1 } END { print sum }'
>199418
0..50 is just for exaggeration that I've fucked up somewhere.
>>215256
I'm from the other thread.
Two things:
You are successively looking at older and older files with the 1..50. The next iteration of mtime 37 will already include the files from mtime 36, so you're inflating the number of found files.
The other problem is a common gotcha: I'm sure you meant to say
find ~/songs \( -iname '*mp3' -o -iname '*ogg' \) -type f ...
Note the gratuitous space around the escaped parantheses. Try your commands on a very simplified example, without the for i 1..50 and you'll see that you get different results on your version if you interchange -iname '*mp3' -o -iname '*ogg', or if you check for ogg first and then the mp3.
>>215267
What I mean to say is:
find THIS -o THAT -type f -THENDOTHIS
will only result in a THENDOTHIS if the THAT matches. There is no trigger on the THENDOTHIS if the THIS matches. You need the parantheses for the two conditional expressions
>>215256One last thing.
Why not
find ~/songs/ -type f -ls | egrep -i ".(mp3|ogg)" | wc -l
>>215271
Now switch it to ogg first and then mp3 and try it again ...
>>215270
jessie@debian:~$ time find ~/songs \( -iname '*.mp3' -o -iname '*.ogg' \) -type f -mtime 0 | wc -l
814
real 0m0.230s
user 0m0.136s
sys 0m0.092s
jessie@debian:~$ time find ~/songs/ -type f -mtime 0 -ls | egrep -i ".(mp3|ogg)" | wc -l
814
real 0m0.151s
user 0m0.044s
sys 0m0.116s
Using ls and egrep is faster. Who'd have thought grep could make it faster?
>>215272
Same output. Thanks it was bugging me for a while.
>>215277
>jessie@debian:~$ time find ~/songs/ -type f -mtime 0 -ls | egrep -i ".(mp3|ogg)" | wc -l
>814
>real 0m0.151s
>user 0m0.044s
>sys 0m0.116s
>jessie@debian:~$ time find ~/songs \( -iname '*.mp3' -o -iname '*.ogg' \) -type f -mtime 0 > 'my list of .mp3 and .ogg files.txt'
>jessie@debian:~$ time find ~/songs/ -type f -mtime 0 -ls | egrep -i ".(mp3|ogg)" | wc -l
>815
>real 0m0.151s
>user 0m0.044s
>sys 0m0.116s
>>215280
What?