Show Results If the Expressions Are True (AND)


Show Results If the Expressions Are True (AND)

find -a

A key feature of find is the ability to join several options to more tightly focus your searches. You can link together as many options as you'd like with -a (or -and). For example, if you want to list every song performed by the world's greatest rock 'n' roll band, the Rolling Stones, you might use just -name "Rolling_Stones*" at first, but that wouldn't necessarily work. Some folders have Rolling_Stones in them, and there may be a soft link or two with the band's name in it as well. We, therefore, also need to use -type f. Combine them as follows:

$ find . -name "Rolling_Stones*" -a -type f 1968_Beggars_Banquet/03_-_Dear_Doctor.mp3 1968_Beggars_Banquet/01_-_Sympathy_For_The_Devil.mp3 1968_Beggars_Banquet/02_-_No_Expectations.mp3 1968_Beggars_Banquet/04_-_Parachute_Woman.mp3 1968_Beggars_Banquet/05_-_Jig-Saw_Puzzle.mp3 1968_Beggars_Banquet/06_-_Street_Fighting_Man.mp3 


That's cool, but how many Stones tunes do we have? Pipe the results of find to wc (which stands for "word count"), but also use the -l option, which gives you the number of lines instead of the word count:

$ find . -name " Rolling_Stones* " -a -type f | wc -l 317 


Three hundred and seventeen Rolling Stones songs. Sweet. In this case, you can always get what you want.

Note

If you have no idea what that last sentence means, get yourself a copy of the album Let It Bleed now. Don't forget to play it loud.




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