Mac View Port Usage

Source: Internet
Author: User

Use Lsof (list open files) under Mac to view port occupancy, lsof is a tool that lists open files for the current system.

Using Lsof lists all the ports that are occupied:

$ lsof

Use less to display pagination, such as:

$ lsof | Less

You can also use-I to see if a port is occupied, such as:

$ lsof-i:3000

If the port is occupied, the relevant information is returned and no information is returned if it is not occupied.

The lsof syntax format is:

lsof [options] FileName

Common list of parameters:

Lsof filename Displays all processes that open the specified file
Lsof-a indicates that two parameters must be met to display the result
lsof-c string   display the command column with all open files for the process that contains the specified characters
Lsof-u Username Displays the file to which the user process is open
Lsof-g GID shows the process that belongs to the GID
lsof +d/dir/The file opened by the process in the directory
Lsof +d/dir/, but will search All directories are recorded in a relatively long time
lsof-d FD Displays the process for the specified file descriptor
Lsof-n does not convert the IP to hostname, by default the-n parameter
Lsof-i to display the condition of the process
lsof-i[46 ] [protocol][@hostname |hostaddr][:service|port]
           ---IPv4 or IPv6
           protocol and TCP or UDP
& nbsp;          hostname--Internet host name
            hostaddr-IPv4 address
       Service name in      service-/etc/service (can be more than one)
            Port-and port number (can be more than one)

To view files whose file type is txt opened by the root user process:

$ lsof-a-u root-d txt

Lsof Other uses:

First, find who is using the file system
When uninstalling a file system, the operation will typically fail if there are any open files in the file system. Then through lsof you can find out which processes are using the file system that is currently being uninstalled, as follows:
# lsof/gtes11/

Ii. Recovery of deleted files
When a Linux computer is compromised, it is common for the log files to be deleted to conceal the attacker's traces. Administrative errors can also cause accidental deletion of important files, such as the active transaction log of the database is accidentally deleted when the old log is cleaned up. These files can sometimes be recovered by lsof.

Mac View Port Usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.