8.2. Listing files using patterns

You can print information about a group of files based on patterns or characters using wildcards.

Wildcard Meaning
* Matches any number of characters
? Matches any single character
[character_class] Matches any character that is a member of the specified character class.

Character Classes:
[:alnum:] Alphanumeric characters
[:alpha:] Alphabetic characters
[:digit:] Numerals
[:upper:] Uppercase alphabetic characters
[:lower:] Lowercase alphabetic characters
[!character_class] Matches any character that is not a member of the specified character class

Pattern Matches
AB* List all the filenames that begin with "AB"
*AB List all the filenames that end with "AB"
AB*.txt List all the filenames that begin with "AB" and end with ".txt"
AB??? List all the filenames that begin with "AB" followed by exactly three characters
[aA]* List all the filenames that begin with "a" or "A"
[aA]?.txt List all the filenames that begin with "a" or "A" followed by one character and ".txt"
[[:upper:]]* List any filenames that begin with an uppercase letter
[![:upper:]]* List any filenames that do not begin with an uppercase letter

$ ls /Volumes/MyDrive/MyFolder/Articles/p*
/Volumes/MyDrive/MyFolder/Articles/patel and shen.pdf
/Volumes/MyDrive/MyFolder/Articles/perez 2013.pdf
/Volumes/MyDrive/MyFolder/Articles/pnas-0502843102.pdf
/Volumes/MyDrive/MyFolder/Articles/pnas.201604898.pdf
/Volumes/MyDrive/MyFolder/Articles/pnas01522-0696.pdf
/Volumes/MyDrive/MyFolder/Articles/poldrack ROI analysis.pdf
/Volumes/MyDrive/MyFolder/Articles/pone.0088419.pdf
/Volumes/MyDrive/MyFolder/Articles/pone.0113807.pdf
/Volumes/MyDrive/MyFolder/Articles/pq004724.pdf
/Volumes/MyDrive/MyFolder/Articles/pq008939.pdf
/Volumes/MyDrive/MyFolder/Articles/precuneus.pdf
/Volumes/MyDrive/MyFolder/Articles/prefrontalCortex.pdf

$ ls /Volumes/MyExternalDrive/Shared/Articles/[pr]*
/Volumes/MyExternalDrive/Shared/Articles/patel and shen.pdf
/Volumes/MyExternalDrive/Shared/Articles/perez 2013.pdf
/Volumes/MyExternalDrive/Shared/Articles/pnas-0502843102.pdf
/Volumes/MyExternalDrive/Shared/Articles/pnas.201604898.pdf
/Volumes/MyExternalDrive/Shared/Articles/pnas01522-0696.pdf
/Volumes/MyExternalDrive/Shared/Articles/poldrack ROI analysis.pdf
/Volumes/MyExternalDrive/Shared/Articles/pone.0088419.pdf
/Volumes/MyExternalDrive/Shared/Articles/pone.0113807.pdf
/Volumes/MyExternalDrive/Shared/Articles/pq004724.pdf
/Volumes/MyExternalDrive/Shared/Articles/pq008939.pdf
/Volumes/MyExternalDrive/Shared/Articles/precuneus.pdf
/Volumes/MyExternalDrive/Shared/Articles/prefrontalCortex.pdf
/Volumes/MyExternalDrive/Shared/Articles/raz 2004.pdf
/Volumes/MyExternalDrive/Shared/Articles/read1_Brain-2006-Ciccarelli-1859-71.pdf
/Volumes/MyExternalDrive/Shared/Articles/read2_6165.pdf

$ ls /Volumes/MyExternalDrive/Shared/Articles/[pr]*.pdf
/Volumes/MyExternalDrive/Shared/Articles/patel and shen.pdf
/Volumes/MyExternalDrive/Shared/Articles/perez 2013.pdf
/Volumes/MyExternalDrive/Shared/Articles/pnas-0502843102.pdf
/Volumes/MyExternalDrive/Shared/Articles/pnas.201604898.pdf
/Volumes/MyExternalDrive/Shared/Articles/pnas01522-0696.pdf
/Volumes/MyExternalDrive/Shared/Articles/poldrack ROI analysis.pdf
/Volumes/MyExternalDrive/Shared/Articles/pone.0088419.pdf
/Volumes/MyExternalDrive/Shared/Articles/pone.0113807.pdf
/Volumes/MyExternalDrive/Shared/Articles/pq004724.pdf
/Volumes/MyExternalDrive/Shared/Articles/pq008939.pdf
/Volumes/MyExternalDrive/Shared/Articles/precuneus.pdf
/Volumes/MyExternalDrive/Shared/Articles/prefrontalCortex.pdf
/Volumes/MyExternalDrive/Shared/Articles/raz 2004.pdf
/Volumes/MyExternalDrive/Shared/Articles/read1_Brain-2006-Ciccarelli-1859-71.pdf
/Volumes/MyExternalDrive/Shared/Articles/read2_6165.pdf

$ ls /Volumes/MyExternalDrive/Shared/Articles/[pr]????????.pdf
/Volumes/MyExternalDrive/Shared/Articles/precuneus.pdf