(Mastering the OS module, you need to understand the operation of common commands under Linux or Unix-like systems)
os.name Indicates the platform you are using. For example, for Windows, it is ‘nt‘ , and for Linux/unix users, it is ‘posix‘ .
os.getcwd() Gets the current working directory, which is the directory path of the current Python script work.
Os.mkdir (' path ') creates a new directory that is a string representing the path to the new directory.
Os.rmdir (' path ' ) removes the empty directory, path is a string that represents the path of the directory you want to delete. Equivalent to the $rmdir command.
Stat ( path ) looks for additional information about the file that the path points to, equivalent to the $ls-l command.
os.listdir( ‘.‘) Returns all file and directory names under the specified directory. ' Represents the current path
os.remove( ‘path‘ ) Used to delete a file
Rename ( src, DST ) renames the file, SRC and DST are two paths, each representing the path before and after renaming.
chmod ( path, mode ) changes the permissions of the file that the path points to. Equivalent to the $chmod command.
Chown ( path, UID, GID ) changes the owner and owning group of the file that the path points to. Equivalent to the $chown command.
os.system()function to run the shell command.
Symlink ( src, DST ) creates a soft link for the file DST, src for the path of the soft link file. Equivalent to the $ln-s command.
os.path.split() The function returns the directory name and file name of a path.
>>> os.path.split (' ~/ETC/VIM/VIMRC ')
(' ~/etc/vim ', ' VIMRC ')
os.path.isfile() and os.path.isdir() the function separately check whether the given path is a file or a directory.
Similarly, the os.path.existe() function is used to verify that the given path really exists
Shutil Bag
Copy (src, DST) copies files from Src to DST. Equivalent to the $CP command.
>>> Import Shutil
>>> shutil.copy (' aa.py ', ' bb.py ')
Move (src, DST) moves files from Src to DST. Equivalent to the $MV command.
Python standard library OS module