restorecon(8)
Restore SELinux security context for files and directories.
Synopsis
restorecon [OPTION]... FILE...Description
restorecon is used to restore the default SELinux security contexts (labels) for files and directories. It reads the SELinux policy configuration to determine what the security context should be, then applies those contexts to the specified files.
This command is useful after restoring files from backup, copying files between systems, or when SELinux security contexts become incorrect or missing. It works recursively on directories and can process entire filesystem trees.
Common options
| Flag | What it does |
|---|---|
-r | Recursive; restore contexts for all files and subdirectories |
-R | Recursive; follow all symbolic links (like -r but follows symlinks) |
-v | Verbose; print files as they are processed |
-n | No changes; show what would be relabeled without making changes |
-e DIRECTORY | Exclude directory from relabeling (can be used multiple times) |
-i | Ignore files that do not exist |
-p | Show progress; display the number of files processed |
-F | Force relabeling; treat all files as unlabeled |
-c | Change only files whose context differs from the default |
-m FILE | Use an alternative SELinux policy file instead of default |
Examples
Restore the default SELinux context for a single file
restorecon /home/user/file.txtRecursively restore contexts for all files in a web directory
restorecon -r /var/www/htmlRecursively restore home directory contexts with verbose output showing each file
restorecon -v -r /homePreview what would be relabeled in /etc without making actual changes
restorecon -n -r /etcRecursively restore /var/log but exclude the archive subdirectory
restorecon -r -e /var/log/archive /var/logRecursively restore the entire filesystem with progress display
restorecon -R -p /Force relabel a file, treating it as if it has no context
restorecon -F /etc/shadow