Question
what does the |
and grep
command do?
Answer
|
Is commonly called a pipe, and like the name sets it creates a way for data from the command written before it to be passed down to the command written after it, for example:
ls -l /etc | less
the first set of commands return a verbose (long) list of files and directories from the /etc
directory which is where configuration files and directories are located, then the pipe passes that list to the less
command which allows us to see the list in a more readable format.
grep
This command stands for global regular expression print, the value passed to it is an expression, and a second value will be a file, it will use the expression to compare it with the content inside the file, anything that contains a match will be returned to the console for us to see, for example, in the exercise the command
env | grep PATH
gets all the environment variables in our session and checks what matches the word PATH
, returning all matches.