Re:A Unix Utility to Know About: lsof (2009)
by devonkim on Friday August 26, 2016 @10:48AM
(#12366646)
Modern Linuxes have pgrep to help avoid the inevitable "lol, the grep process I fired will match" issue that results in having to filter that out as well with yet another program.
[ Parent
| on HN ]
Re:A Unix Utility to Know About: lsof (2009)
by smhenderson on Friday August 26, 2016 @12:37PM
(#12367401)
Yeah, I always felt having to type the extra bit was strange, like maybe grep could have a switch to say "don't find grep" but I guess having a switch for such a specific use case, grepping processes, is overkill.
Anyway, it's just a reflex now to always:
ps aux | grep <program> | grep -v grep
Re:A Unix Utility to Know About: lsof (2009)
by amyjess on Friday August 26, 2016 @02:21PM
(#12368194)
You can also surround each character in the program's name with square brackets.
ps -ef | grep [p][r][o][g][r][a][m]
Re:A Unix Utility to Know About: lsof (2009)
by smhenderson on Monday August 29, 2016 @12:11PM
(#12382872)
Yes, I never knew that. But I saw it in another post and as the sibling post mentions it's enough to surround just the first character with the brackets...
This is why I love HN, I learn stuff I never knew I wanted to know!
Re:A Unix Utility to Know About: lsof (2009)
by jpitz on Friday August 26, 2016 @02:51PM
(#12368418)
You only need surround one character.
Re:A Unix Utility to Know About: lsof (2009)
by nocman on Friday August 26, 2016 @01:07PM
(#12367645)
One problem with pgrep is it has no option to ignore case.
Yes, I do sometimes have processes with camel-cased names which I may or may not remember exactly. So you:
ps auwx | grep -i {lc-version-of-camel-cased-name}