lsof

The command

Lsof -i: indicates the port number

View the results

# lsof -i:8000
COMMAND   PID USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
nodejs  26993 root   10u  IPv4 37999514      0t0  TCP *:8000 (LISTEN)
Copy the code

Input Parameter Description

TXT: displays the open file abc. TXT lsof -c ABC: displays the open file lsof -c -p 1234: Lsof +d /usr/local/ : displays the files opened by the process whose process ID is 1234. Lsof +d /usr/local/ : displays the files opened by the process whose process ID is 1234. Lsof -d 4: displays the process whose fd is 4. Lsof -I -U: displays all open ports and UNIX domain filesCopy the code

Parameter Description

  • COMMAND: indicates the process name
  • PID: indicates the process id
  • USER: indicates the process owner
  • FD: file descriptor. The application program identifies the file by the file descriptor, such as CWD \ TXT
  • TYPE: indicates the file TYPE, such as DIR\REG
  • DEVICE: Specifies the disk name
  • SIZE: indicates the file SIZE
  • NODE: index NODE (file identifier on disk)
  • NAME: Indicates the exact NAME of the open file

Pay attention to

Lsof -i requires the permission of user root

netstat

The command

Netstat tunlp | grep port number

View the results

8000 TCP 0 0 # netstat tunlp | grep 0.0.0.0:8000 0.0.0.0: * 26993 / nodejs LISTENCopy the code

Input Parameter Description

-t (TCP) displays only TCP related options -u (udp) displays only UDP related options -n Refuses to display aliases. All numbers that can be displayed are converted to numbers. -l Lists only the service status in ListenCopy the code

More orders

Netstat NTLP / / view all current TCP port netstat ntulp | grep / 80 / see all 80 port usage netstat ntulp | grep / 3306 / see all 3306 port usageCopy the code