Semanage / Delete User Defined File Labeling Rule Linux
Delete User Defined File Labeling Rule Linux
Use the semanage command to delete a user-defined file labeling rule for SELinux contexts.
$
Terminal sudo semanage fcontext -d '</mnt/share(/.*)?>' sudo semanage fcontext -d '</mnt/share(/.*)?>' #!/bin/bash
# Delete User Defined File Labeling Rule Linux
sudo semanage fcontext {{[-d|--delete]}} '{{/mnt/share(/.*)?}}' import subprocess
# Delete User Defined File Labeling Rule Linux
# Make sure to replace <placeholders> with actual values
def run_command():
cmd = [
"semanage",
"semanage",
"fcontext",
"-d",
"'</mnt/share(/.*)?>'"
]
try:
print(f"Executing: {' '.join(cmd)}")
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
except FileNotFoundError:
print("Error: semanage not found. Please install it first.")
if __name__ == "__main__":
run_command() When To Use
This command is used to remove specific SELinux file labeling rules.
Warning
Destructive operation. Confirm the target path and keep a backup before executing.
Command Builder
Tune the command before you copy it
$
Generated Command sudo semanage fcontext -d '</mnt/share(/.*)?>' Terminal Output
Expected runtime feedback
>
Output Removing context for '/mnt/share':
Context removed successfully. Command Breakdown
What each part is doing
-
sudo - Base Command
- The executable that performs this operation. Here it runs Semanage before the shell applies any redirect operators.
-
-d - d| delete
- The value supplied for d| delete.
-
</mnt/share(/.*)?> - mnt share( .*)?
- The value supplied for mnt share( .*)?.
-
-d - Command Option
- Tool-specific option used by this command invocation.
How To Run
Execution path
- Step 1
Run the command with sudo privileges.
- Step 2
Specify the -d or --delete option to remove the rule.
- Step 3
Provide the path pattern for the file context to delete.
Alternative Approaches
Comparable commands in other tools
Alternative tools that share the "manage-files" operation intent.
Git / Create Git Repo Current Directory Commit All Files
git setup Tmsu / Tag Multiple Files tmsu tag --tags "<music mp3>" <*.mp3> Base64 / Decode File To Stdout base64 -d -i <path/to/file> Fsadm / Dry Run Resize Filesystem Linux fsadm -n resize </dev/vg_name/lv_name> <10G> Fsadm / Grow Filesystem Full Device Linux fsadm resize </dev/vg_name/lv_name>