Im gonna try and answer this with a straight-forward practial answer:
The pipe |
lets you do awesome stuff in the shell! It's the one single operator that i consider the most usefull and mighty.
how about counting files in a directory? simple:
ls | wc -l
..redirect the output of ls
to wc
wit parameter -l
for lines
or counting of lines in a file?
cat someFile | wc -l
what if i want to search for something? 'grep' can search for occurences of strings:
cat someFile | grep aRandomStringYouWantToSearchFor
you just redirect the output of the command left of the Pipe to the command right of the pipe.
one more level: how often does something occure in a file?
cat someFile | grep aRandomStringYouWantToSearchFor | wc -l
you can use the | for nearly everything :)
fortune | cowsay

sudo
to runps -ef
. Also a common trick to avoid the third command is enclosing a character of the process' name in square brackets:ps -ef | grep [p]rocessname
ps -ef | grep '[p]rocessname'
grep [p]rocessname
, you are telling the shell to look for a file in the current directory with the nameprocessname
and substitute the pattern with the name of that file. If no file namedprocessname
exists, the shell may pass the pattern literally to grep. But that depends on your settings. So your version will break if a file namedprocessname
exists or if any of the following shell options has been enabledfailglob
,nullglob
,nocaseglob
.