Random linux stuff
I regularly need to filter and modify text output from commands, but when I don’t using them often enough I tend to forget the syntax I used (or why I used it). This is a collection of command filters as a reminder to me, and may help out others.
Getting the last word in a line – OS:CentOS
>$ echo 'The lazy dog jumped over the quick brown fox.' | sed -e 's/.* //g' fox. >$ echo 'The lazy dog jumped over the quick brown fox.' | awk '{print $NF}' fox.
Both ways work; the second works even if there’s a trailing space.
Need to find a process/port running. CentOS /usr/sbin/lsof
sudo lsof -Pni | grep snmp snmpd 31823 snmp 7u IPv4 3810858 UDP *:161 snmpd 31823 snmp 9u IPv6 3810863 UDP *:161 snmpd 31823 snmp 10u IPv4 3810864 TCP *:161 (LISTEN) snmpd 31823 snmp 11u IPv6 3810866 TCP *:161 (LISTEN) snmptrapd 31826 root 8u IPv4 3810878 UDP *:162 snmptrapd 31826 root 9u IPv6 3810882 UDP *:162