Show Results If Either Expression Is True (OR)


Show Results If Either Expression Is True (OR)

find -o

Earlier, in the section "Find Files by File Size," we saw that we could use find to list every Clash song on London Calling that was exactly 10MB, and we could use find to list songs on London Calling that were more than 10MB, but we couldn't do both at the same time with -size. In the previous section, we saw that -a combines options using AND; however, we can also utilize -o (or -or) to combine options using OR.

So, in order to find songs from London Calling that are 10MB or larger, we use the following command:

$ cd London_Calling $ find . -size +10M -o -size 10M 03_-_Jimmy_Jazz.ogg 07_-_The_Right_Profile.ogg 08_-_Lost_In_The_Supermarket.ogg 09_-_Clampdown.ogg 12_-_Death_Or_Glory.ogg 15_-_Lover's_Rock.ogg 18_-_Revolution_Rock.ogg (25th_Anniversary)_-_18_-_Revolution_Rock.mp3 (25th_Anniversary)_-_37_-_Heart_And_Mind.mp3 (25th_Anniversary)_-_ 39_-_London_Calling_(Demo).mp3 


Oops...we also got results from the 25th Anniversary release of London Calling as well, which we didn't want. We need to do two things: exclude results from the 25th Anniversary edition and make sure that our OR statement works correctly.

To exclude the 25th Anniversary songs, we add ! -name "*25*" at the end of our command. To make sure that OR works, we need to surround it with parentheses, which combines the statements. However, you need to escape the parentheses with backslashes so the shell doesn't misinterpret them, and you also need to put spaces before and after your statement. The combination gives us this command:

$ cd London_Calling $ find . \( -size +10M -o -size 10M \) ! -name "*25*" 03_-_Jimmy_Jazz.ogg 07_-_The_Right_Profile.ogg 08_-_Lost_In_The_Supermarket.ogg 09_-_Clampdown.ogg 12_-_Death_Or_Glory.ogg 15_-_Lover's_Rock.ogg 18_-_Revolution_Rock.ogg 


Perfect. Seven songs are 10MB or greater in size.

Note

Read about London Calling at Allmusic.com (www.allmusic.com/cg/amg.dll?p=amg&sql=10:aeu1z82ajyvn) or Pitchfork (www.pitchforkmedia.com/record-reviews/c/clash/london-calling.shtml).


We can also use -o to find out how many songs we have on the music drive. We might start with this command, which we run from the root of /media/music, and which uses -a (be patient; we'll get to -o):

$ find . -name "*mp3*" -a -type f | wc -l 23407 


Twenty-three thousand? That's not right. Ah, now it's obvious. We were only searching for mp3 files, and an enormous amount of songs was encoded in the superior Ogg Vorbis format, a patent-free, open source alternative to mp3. Let's look for mp3 or ogg files and count the results with wc l:

$ find . \( -name "*mp3*" -o -name "*.ogg*" \) -a -type f | wc -l 41631 


That sounds much better, but there are also some FLAC files on there. Let's add another -o to the mix:

$ find . \( -name "*mp3*" -o -name "*.ogg*" -o -name "*.flac*" \) -a -type f | wc -l 42187 


Now that's more like it: 42,000 songs and growing!



Linux Phrasebook
Linux Phrasebook
ISBN: 0672328380
EAN: 2147483647
Year: 2007
Pages: 288

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net