Tag: #fuser

Who uses this port?

Today I will give you a pretty one-liner, fetching programs using port passed as the parameter.

# for i in $(fuser 22/tcp); do cat /proc/$i/cmdline; echo ""; done

The main part is the fuser command which retrieves PID. There may be many processes using this port as a client, so we need to loop on them with for. The cmdline content does not include a new-line character, so we add it with echo "". The sample output is following:

# for i in $(fuser 22/tcp); do cat /proc/$i/cmdline; echo ""; done
/usr/sbin/sshd
sshd: root@pts/0

The same way may be used to check file usage or UDP port.