Python for System administrator [OS Functions]

Friday, May 9, 2014

Intro


The OS Module in Python provides a good way to use the operation system functionality.
The functions provided allows to interface with the underlying OS that Python is running on (Windows, Mac or Linux).

Os Functions


♦ Executing a shell command : os.system()
♦ Get the status of a file: os.stat()
♦ Get the users environment: os.environ()
♦ Move to a different direcoty: os.chdir()
♦ Get current working directory: os.getcwd()
♦ Get the group Id of the current process: os.getgid()
♦ Get the current process's user id: os.getuid()
♦ Get the real process ID of the current process: os.getpid()
♦ Get the name of the user logged: os.getlogin()
Check read permissions: os.getaccess()
♦ Change the mode of path to numeric mode: os.chmod()
♦ Change the owner and group id: os.chown()
♦ Set the current numeric unmask: os.umask(mask)
♦ Get the size of a file: os.getsize()
♦ Get the current environment: os.getenviron()
♦ Return informations about the operating system: os.uname()
♦ Delete the file path: os.remove(path)
♦ Remove the directory path: os.rmdir(path)
♦ Print out all directories, sub-directories and files: os.walk()
♦ Check if a path exists: os.path.exists()
♦ Get load average: os.getloadavg()



No comments:

Post a Comment