LinuxCommandLibrary

ports

View FreeBSD Ports Collection information

TLDR

Update the ports tree

$ ports -u
copy

List the ports in the current tree
$ ports -l
copy

Check the differences between installed packages and the ports tree
$ ports -d
copy

SYNOPSIS

ports

DESCRIPTION

The `ports` command displays a list of currently assigned TCP and UDP ports. It retrieves this information from the `/etc/services` file. The command provides a quick reference for well-known port assignments, making it useful for network administrators and developers.

While the command provides a convenient listing, it does not show currently active connections. Use commands like `netstat`, `ss`, or `lsof` to see which processes are actively using specific ports. The command is deprecated and may not be available on modern systems, with alternatives such as `grep` with `/etc/services` being preferred. On some systems the command may call `rpcinfo -p`.

Its primary benefit is offering a simple, human-readable output of standard port assignments without needing to parse complex output from other network utilities. Keep in mind that the information represents assigned ports, not necessarily actively used or accessible ports.

CAVEATS

The `ports` command is deprecated and may not be present on all Linux distributions. It provides information only from `/etc/services` and does not indicate active connections. The command's output is static and reflects the contents of the services file, not the current state of the network.

FILE SOURCE

The command gets its information from the `/etc/services` file. This file contains mappings between service names, port numbers, and protocol types (TCP or UDP).

ALTERNATIVES

Using `grep` to search `/etc/services` allows more specific queries, for example: `grep 'ssh' /etc/services`. Tools like `ss` or `netstat` show active connections, providing a dynamic view of port usage. `rpcinfo -p` shows registered RPC services.

EXAMPLE OUTPUT

The output typically includes the service name, the port number/protocol, and any aliases for the service. For example:

ssh 22/tcp # Secure Shell
smtp 25/tcp # Simple Mail Transfer

HISTORY

The `ports` command was a utility primarily found on older Unix systems to quickly list the known service names and port numbers as defined in the `/etc/services` file. Its usage has declined significantly due to the availability of more powerful and versatile networking tools, such as `netstat`, `ss`, and `lsof`, that provide real-time connection information and detailed process insights. Today, using `grep` on `/etc/services` is commonly used to achieve the same result.

SEE ALSO

netstat(1), ss(1), lsof(1), grep(1), rpcinfo(1)

Copied to clipboard