Python os.lchflags() Method
os.lchflags() Overview
The os.lchflags() method is used to set the path’s flags to numeric flags, similar to chflags(), but without the soft links.
Only supported for use under Unix.
os.lchflags() Syntax
The syntax format of the lchflags() method is as follows:
os.lchflags(path, flags)
os.lchflags() Parameters
- path – Sets the path to the tagged file
- flags – can be a combination of one or more tags, multiple separated by
|
.- UF_NODUMP: Non-dumped files
- UF_IMMUTABLE: The file is read-only
- UF_APPEND: Files can only be appended
- UF_NOUNLINK: Files cannot be deleted
- UF_OPAQUE: Directory is not transparent and needs to be viewed through the union stack
- SF_ARCHIVED: Archivable files (super user settable)
- SF_IMMUTABLE: The file is read-only (super user can set it)
- SF_APPEND: File can only be appended (super user can set)
- SF_NOUNLINK: File cannot be deleted (super user can set)
- SF_SNAPSHOT: Snapshot file (super user settable)
os.lchflags() Return Value
This method has no return value.
os.lchflags() Demo#1
The following example demonstrates the use of the lchflags() method.
#!/usr/bin/python3
import os, sys
# Open file
path = "/root/apidemos.com.txt"
fd = os.open( path, os.O_RDWR|os.O_CREAT )
# Close file
os.close( fd )
# Modify file tags
ret = os.lchflags(path, os.UF_IMMUTABLE )
print ("Modify file marker success!!!")
Output:
Modify file marker success!!!