ls ~/Downloads | grep .jpg
Grep will list them all out and highlight the “.jpg” part since it’s what you searched for.
You pipe the output (with the command “|”) of just about any command into
grep
. If you have a plain text file laying around, cat
it out and pipe the result into Grep to find a specific word.cat file.txt | grep word
Grep will print out any lines in the file containing the word that you told it to look for.
Unix-like systems are case sensitive, meaning that “Ubuntu” is completely different than “ubuntu.” That can be a pain when searching for something. Grep has a flag to eliminate the problem. Add the
-i
flag to your search, and Grep will ignore case.ls ~/Downloads | grep -i Ubuntu
No comments:
Post a Comment