echo and grep
Explore how to use echo to check glob patterns and grep to search text within files and directories, including recursive searches, handling hidden files, and filtering results. Learn the differences in options and tools for searching text and handling non-text files.
We'll cover the following...
There is an option to check how the Bash expands a glob pattern. Use the echo command for that. Below are echo calls for checking the patterns:
echo *
echo ~/*
echo /*
The first one lists files in the current directory. The second and third command does the same for the home directory and the root directory, respectively.
Run the commands discussed in this lesson in the terminal below.
Don’t enclose search patterns in double quotes. Below is an example of the wrong command:
grep "free software" "*"
Quotes prevent the Bash expansion. Therefore, Bash does not insert the file names to the command but passes the asterisk to the grep utility. The utility cannot handle the glob pattern properly, like find does. So, we’ll get an error as shown in the following ...