Show Results If the Expression Is Not True (NOT)


Show Results If the Expression Is Not True (NOT)

find -n

We have already used ! to negate expressions in earlier sections in this chapter (see "Find Files By Ownership" and "Show Results If Either Expression Is True (OR)"), but let's take another, longer look at this operator. In the previous section, we used find to determine how many mp3, ogg, and flac files we have on the music drive. But how many total files do we have on the drive?

$ find . -name "* " | wc -l 52111 


Hmm...52,000 total files, but only 42,000 are mp3, ogg, or flac. What are the others? Let's construct a find command that excludes files that end in .mp3, .ogg, or .flac while also excluding directories. Wrap these four conditions in parentheses, and then place ! before the command to indicate our wish to negate these items and instead look for things that do not match these specifications:

$ find . ! \( -name "*mp*" -o -name "*ogg" -o -name "*flac" -o -type d \) ./Folk/Joan_Baez/Joan_Baez_-_Imagine.m3u ./500_Greatest_Singles/singles.txt ./Blues/Muddy_Waters/Best_Of.m3u ./Blues/Robert_Johnson/Hellhound_On_My_Trail.MP3 ./Blues/Johnny_Winter/Johnny_Winter.m3u [Results truncated for length] 


Now we have the answer, or at least we're starting to get an answer. We have m3u (playlist) files, text files, and files that end in MP3 instead of mp3 (we also have JPEGs, GIFs, and even music videos). The find command, like all of Linux, is case-sensitive (as discussed in Chapter 1), so a search for "*mp3*" will not turn up songs that have the .MP3 suffix. Is there any quick and easy way to change these files so that they have the correct, lowercase extension? Sure. And we'll use find to do it.



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