LOGBOOK

HELP

Quiz Entry - updated: 2026.06.20

How do you view SELinux contexts for processes and files?

Add -Z to the usual tools: ps auxZ shows process contexts, ls -Z shows file contexts, id -Z shows your own — -Z is the universal "show me the SELinux label" flag.

This one letter is the workhorse of SELinux troubleshooting, because most problems come down to "what label does this actually have, and is it the one policy expects?" The same -Z extends to commands that create things (cp -Z, mkdir -Z) so you can set the right context as you go rather than fixing it afterward.

View process contexts:

# All processes with SELinux context
ps auxZ
# Specific process
ps -ZC httpd

View file contexts:

# Files in directory
ls -Z /var/www
# Single file with details
ls -laZ file.txt

View directory context:

ls -dZ /var/www/html

Example output:

[root@host ~]# ls -Z /var/www
drwxr-xr-x. root root system_u:object_r:httpd_sys_script_exec_t:s0 cgi-bin
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 html

Other commands supporting -Z:

  • cp -Z - copy with context
  • mkdir -Z - create directory with context
  • id -Z - current user's SELinux context

From Quiz: LIOS / SELinux Security | Updated: Jun 20, 2026