lsns is a Linux command that displays information about the namespaces in a Linux system. Namespaces are a feature of the Linux kernel that allow for the creation of isolated environments for processes. These environments can have their own set of system resources such as network interfaces, process IDs, mounts, and other system objects.
lsns provides information about all the namespaces present on the system or about a specific namespace specified with the -t option. This information can include the namespace ID, the type of namespace, and the PID of the process that created the namespace.
The output of lsns can be useful for troubleshooting and monitoring purposes. For example, you can use it to see the namespaces associated with a specific process or to find the type of namespace associated with a process. Additionally, lsns can be used to get a snapshot of the namespaces present on the system and their relationships with other namespaces and processes.
If you encounter the below error while running the command lsns:
lsns: command not found
you may try installing the below package as per your choice of distribution:
Distribution | Command |
---|---|
Debian | apt-get install util-linux |
Ubuntu | apt-get install util-linux |
Alpine | apk add util-linux |
Arch Linux | pacman -S util-linux |
Kali Linux | apt-get install util-linux |
CentOS | yum install util-linux |
Fedora | dnf install util-linux |
OS X | brew install util-linux |
Raspbian | apt-get install util-linux |
lsns Command Examples
1. List all namespaces:
# lsns
2. List namespaces in JSON format:
# lsns --json
3. List namespaces associated with {{pid}}:
# lsns --task pid
4. List the specified type of namespaces only:
# lsns --type
5. List namespaces, only showing the namespace ID, type, PID, and command:
# lsns --output NS,TYPE,PID,COMMAND