Easy Tutorial
❮ Python Os Getcwdb Python Func Number Log ❯

Python3 os.chroot() Method

Python3 OS File/Directory Methods


Overview

The os.chroot() method is used to change the root directory of the current process to the specified directory. Administrator privileges are required to use this function.

This method is effective in Unix systems.

Syntax

The syntax for the chroot() method is as follows:

os.chroot(path);

Parameters

-

path -- The directory to be set as the root directory.

Return Value

This method does not return any value.

Example

The following example demonstrates the use of the chroot() method:

#!/usr/bin/python3

import os, sys

# Set the root directory to /tmp

os.chroot("/tmp")

print("Root directory changed successfully!!")

Executing the above program will output:

Root directory changed successfully!!

Python3 OS File/Directory Methods

❮ Python Os Getcwdb Python Func Number Log ❯