---

Finding Things on Linux and Understanding Regular Expressions

“There’s some basic regexp-type provision built into the shell:
the most basic example of this is the * wildcard. This example will
list every file in the current directory which has a .jpg
extension:

ls *.jpg

“What actually happens here is that the shell expands the *
before it passes the file list to ls. So that line is really
equivalent to

ls file1.jpg file2.jpg ...

“In contrast, this command-line will produce the same output,
but using grep with full regexp syntax (see the next section for
more on grep):

ls | grep '.*.jpg'

“This runs ls on the current directory (so listing all files),
then passes the output through grep, which uses ‘proper’ regexps,
rather than the shell built-in.”

Complete
Story

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends, & analysis